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

OneParameterCommand::getParameterDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
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  Reaby
19
 * @package eXpansion\Bundle\AdminChat\ChatCommand
20
 */
21
class OneParameterCommand extends AbstractConnectionCommand
22
{
23
    /**
24
     * Description of the parameter
25
     *
26
     * @var string
27
     */
28
    protected $parameterDescription;
29
30
    /**
31
     * Description of the command.
32
     *
33
     * @var string
34
     */
35
    protected $description;
36
37
    /**
38
     * Message to display in chat.
39
     *
40
     * @var string
41
     */
42
    protected $chatMessage;
43
44
    /**
45
     * Name of the dedicated function to call.
46
     *
47
     * @var string
48
     */
49
    protected $functionName;
50
51
    /**
52
     * OneParameterCommand constructor.
53
     *
54
     * @param $command
55
     * @param string $permission
56
     * @param array $aliases
57
     * @param AdminGroups $description
0 ignored issues
show
Documentation introduced by
There is no parameter named $description. Did you maybe mean $parameterDescription?

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...
58
     * @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...
59
     * @param ChatNotification $functionName
60
     * @param PlayerStorage $parameterDescription
61
     * @param AdminGroups $adminGroupsHelper
62
     * @param Connection $connection
63
     * @param ChatNotification $chatNotification
64
     * @param PlayerStorage $playerStorage
65
     * @param LoggerInterface $logger
66
     * @param Time $timeHelper
67
     */
68 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...
69
        $command,
70
        $permission,
71
        array $aliases = [],
72
        $functionName,
73
        $parameterDescription,
74
        AdminGroups $adminGroupsHelper,
75
        Connection $connection,
76
        ChatNotification $chatNotification,
77
        PlayerStorage $playerStorage,
78
        LoggerInterface $logger,
79
        Time $timeHelper
80
    ) {
81 1
        parent::__construct(
82 1
            $command,
83 1
            $permission,
84 1
            $aliases,
85 1
            $adminGroupsHelper,
86 1
            $connection,
87 1
            $chatNotification,
88 1
            $playerStorage,
89 1
            $logger,
90 1
            $timeHelper
91
        );
92
93 1
        $this->description = 'expansion_admin_chat.' . strtolower($functionName) . '.description';
94 1
        $this->chatMessage = 'expansion_admin_chat.' . strtolower($functionName) . '.msg';
95 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...
96 1
        $this->parameterDescription = $parameterDescription;
0 ignored issues
show
Documentation Bug introduced by
It seems like $parameterDescription of type object<eXpansion\Framewo...\Storage\PlayerStorage> is incompatible with the declared type string of property $parameterDescription.

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...
97 1
    }
98
99
100
    /**
101
     * @inheritdoc
102
     */
103 1
    protected function configure()
104
    {
105 1
        parent::configure();
106
107 1
        $this->inputDefinition->addArgument(
108 1
            new InputArgument('parameter', InputArgument::REQUIRED, $this->parameterDescription)
109
        );
110 1
    }
111
112
    /**
113
     * @inheritdoc
114
     */
115 1 View Code Duplication
    public function execute($login, InputInterface $input)
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...
116
    {
117 1
        $nickName = $this->playerStorage->getPlayerInfo($login)->getNickName();
118 1
        $parameter = $input->getArgument('parameter');
119 1
        $group = $this->getGroupLabel($login);
120
121 1
        $this->chatNotification->sendMessage(
122 1
            $this->chatMessage,
123 1
            $this->isPublic ? null : $login,
124 1
            ['%adminLevel%' => $group, '%admin%' => $nickName, "%parameter%" => $parameter]
125
        );
126
127 1
        $this->connection->{$this->functionName}($parameter);
128 1
    }
129
}
130