Completed
Pull Request — master (#106)
by De Cramer
03:01
created

ReasonUserCommand::setChatMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace eXpansion\Bundle\AdminChat\ChatCommand;
4
5
use eXpansion\Framework\AdminGroups\Helpers\AdminGroups;
6
use eXpansion\Framework\Core\Helpers\ChatNotification;
7
use eXpansion\Framework\Core\Helpers\Time;
8
use eXpansion\Framework\Core\Storage\PlayerStorage;
9
use Maniaplanet\DedicatedServer\Connection;
10
use Monolog\Logger;
11
use Psr\Log\LoggerInterface;
12
use Symfony\Component\Console\Input\InputArgument;
13
use Symfony\Component\Console\Input\InputInterface;
14
15
/**
16
 * Class ReasonUserCommand
17
 *
18
 * @author    de Cramer Oliver<[email protected]>
19
 * @copyright 2017 Smile
20
 * @package eXpansion\Bundle\AdminChat\ChatCommand
21
 */
22
class ReasonUserCommand extends AbstractConnectionCommand
23
{
24
    /**
25
     * Description of the login parameter
26
     *
27
     * @var string
28
     */
29
    protected $parameterLoginDescription;
30
31
    /**
32
     * Description of the reason parameter.
33
     *
34
     * @var string
35
     */
36
    protected $parameterReasonDescription;
37
38
    /**
39
     * Description of the command.
40
     *
41
     * @var string
42
     */
43
    protected $description;
44
45
    /**
46
     * Message to display in chat.
47
     *
48
     * @var string
49
     */
50
    protected $chatMessage;
51
52
    /**
53
     * Name of the dedicated function to call.
54
     *
55
     * @var string
56
     */
57
    protected $functionName;
58
59
    /**
60
     * ReasonUserCommand constructor.
61
     *
62
     * @param $command
63
     * @param string $permission
64
     * @param array $aliases
65
     * @param AdminGroups $description
0 ignored issues
show
Documentation introduced by
There is no parameter named $description. Did you maybe mean $parameterLoginDescription?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
66
     * @param Connection $chatMessage
0 ignored issues
show
Bug introduced by
There is no parameter named $chatMessage. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
67
     * @param ChatNotification $functionName
68
     * @param PlayerStorage $parameterLoginDescription
69
     * @param LoggerInterface $parameterReasonDescription
70
     * @param AdminGroups $adminGroupsHelper
71
     * @param Connection $connection
72
     * @param ChatNotification $chatNotification
73
     * @param PlayerStorage $playerStorage
74
     * @param LoggerInterface $logger
75
     * @param Time $timeHelper
76
     */
77 1 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
        $command,
79
        $permission,
80
        array $aliases = [],
81
        $functionName,
82
        $parameterLoginDescription,
83
        $parameterReasonDescription,
84
        AdminGroups $adminGroupsHelper,
85
        Connection $connection,
86
        ChatNotification $chatNotification,
87
        PlayerStorage $playerStorage,
88
        LoggerInterface $logger,
89
        Time $timeHelper
90
    ) {
91 1
        parent::__construct(
92 1
            $command,
93 1
            $permission,
94 1
            $aliases,
95 1
            $adminGroupsHelper,
96 1
            $connection,
97 1
            $chatNotification,
98 1
            $playerStorage,
99 1
            $logger,
100 1
            $timeHelper
101
        );
102
103 1
        $this->description = 'expansion_admin_chat.' . strtolower($functionName) . '.description';
104 1
        $this->chatMessage = 'expansion_admin_chat.' . strtolower($functionName) . '.msg';
105 1
        $this->functionName = $functionName;
0 ignored issues
show
Documentation Bug introduced by
It seems like $functionName of type object<eXpansion\Framewo...lpers\ChatNotification> is incompatible with the declared type string of property $functionName.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
106 1
        $this->parameterLoginDescription = $parameterLoginDescription;
0 ignored issues
show
Documentation Bug introduced by
It seems like $parameterLoginDescription of type object<eXpansion\Framewo...\Storage\PlayerStorage> is incompatible with the declared type string of property $parameterLoginDescription.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
107 1
        $this->parameterReasonDescription = $parameterReasonDescription;
0 ignored issues
show
Documentation Bug introduced by
It seems like $parameterReasonDescription of type object<Psr\Log\LoggerInterface> is incompatible with the declared type string of property $parameterReasonDescription.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
108 1
    }
109
110
111
    /**
112
     * @inheritdoc
113
     */
114 1
    protected function configure()
115
    {
116 1
        parent::configure();
117
118 1
        $this->inputDefinition->addArgument(
119 1
            new InputArgument('login', InputArgument::REQUIRED, $this->parameterLoginDescription)
120
        );
121 1
        $this->inputDefinition->addArgument(
122 1
            new InputArgument('reason', InputArgument::REQUIRED, $this->parameterReasonDescription)
123
        );
124 1
    }
125
126
127
    /**
128
     * @inheritdoc
129
     */
130 1
    public function execute($login, InputInterface $input)
131
    {
132 1
        $nickName = $this->playerStorage->getPlayerInfo($login)->getNickName();
133 1
        $playerLogin = $input->getArgument('login');
134 1
        $reason = $input->getArgument('reason');
135 1
        $group = $this->getGroupLabel($login);
136
137 1
        $playerNickName = $this->playerStorage->getPlayerInfo($playerLogin)->getNickName();
138
139 1
        $this->chatNotification->sendMessage(
140 1
            $this->chatMessage,
141 1
            $this->isPublic ? null : $login,
142 1
            ['%adminLevel%' => $group, '%admin%' => $nickName, '%player%' => $playerNickName, "%reason%" => $reason]
143
        );
144
145 1
        $this->connection->{$this->functionName}($playerLogin, $reason);
146 1
    }
147
}
148