Completed
Pull Request — master (#165)
by
unknown
02:54
created

ReasonUserCommand::execute()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3.2289

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
ccs 12
cts 17
cp 0.7059
cc 3
eloc 17
nc 3
nop 2
crap 3.2289
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 Psr\Log\LoggerInterface;
11
use Symfony\Component\Console\Input\InputArgument;
12
use Symfony\Component\Console\Input\InputInterface;
13
14
/**
15
 * Class ReasonUserCommand
16
 *
17
 * @author    de Cramer Oliver<[email protected]>
18
 * @copyright 2017 eXpansion
19
 * @package   eXpansion\Bundle\AdminChat\ChatCommand
20
 */
21
class ReasonUserCommand extends AbstractConnectionCommand
22
{
23
    /**
24
     * Description of the login parameter
25
     *
26
     * @var string
27
     */
28
    protected $parameterLoginDescription;
29
30
    /**
31
     * Description of the reason parameter.
32
     *
33
     * @var string
34
     */
35
    protected $parameterReasonDescription;
36
37
    /**
38
     * Description of the command.
39
     *
40
     * @var string
41
     */
42
    protected $description;
43
44
    /**
45
     * Message to display in chat.
46
     *
47
     * @var string
48
     */
49
    protected $chatMessage;
50
51
    /**
52
     * Name of the dedicated function to call.
53
     *
54
     * @var string
55
     */
56
    protected $functionName;
57
58
    /**
59
     * ReasonUserCommand constructor.
60
     *
61
     * @param                  $command
62
     * @param string           $permission
63
     * @param array            $aliases
64
     * @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...
65
     * @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...
66
     * @param ChatNotification $functionName
67
     * @param PlayerStorage    $parameterLoginDescription
68
     * @param LoggerInterface  $parameterReasonDescription
69
     * @param AdminGroups      $adminGroupsHelper
70
     * @param Connection       $connection
71
     * @param ChatNotification $chatNotification
72
     * @param PlayerStorage    $playerStorage
73
     * @param LoggerInterface  $logger
74
     * @param Time             $timeHelper
75
     */
76 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...
77
        $command,
78
        $permission,
79
        array $aliases = [],
80
        $functionName,
81
        $parameterLoginDescription,
82
        $parameterReasonDescription,
83
        AdminGroups $adminGroupsHelper,
84
        Connection $connection,
85
        ChatNotification $chatNotification,
86
        PlayerStorage $playerStorage,
87
        LoggerInterface $logger,
88
        Time $timeHelper
89
    ) {
90 1
        parent::__construct(
91 1
            $command,
92 1
            $permission,
93 1
            $aliases,
94 1
            $adminGroupsHelper,
95 1
            $connection,
96 1
            $chatNotification,
97 1
            $playerStorage,
98 1
            $logger,
99 1
            $timeHelper
100
        );
101
102 1
        $this->description = 'expansion_admin_chat.'.strtolower($functionName).'.description';
103 1
        $this->chatMessage = 'expansion_admin_chat.'.strtolower($functionName).'.msg';
104 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...
105 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...
106 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...
107 1
    }
108
109
110
    /**
111
     * @inheritdoc
112
     */
113 1
    protected function configure()
114
    {
115 1
        parent::configure();
116
117 1
        $this->inputDefinition->addArgument(
118 1
            new InputArgument('login', InputArgument::REQUIRED, $this->parameterLoginDescription)
119
        );
120 1
        $this->inputDefinition->addArgument(
121 1
            new InputArgument('reason', InputArgument::REQUIRED, $this->parameterReasonDescription)
122
        );
123 1
    }
124
125
126
    /**
127
     * @inheritdoc
128
     */
129 1
    public function execute($login, InputInterface $input)
130
    {
131 1
        $nickName = $this->playerStorage->getPlayerInfo($login)->getNickName();
132 1
        $playerLogin = $input->getArgument('login');
133 1
        $reason = $input->getArgument('reason');
134 1
        $group = $this->getGroupLabel($login);
135
136 1
        $playerNickName = $this->playerStorage->getPlayerInfo($playerLogin)->getNickName();
137
        try {
138 1
            $this->connection->{$this->functionName}($playerLogin, $reason);
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
        } catch (\Exception $e) {
145
            $this->chatNotification->sendMessage(
146
                'expansion_admin_chat.dedicatedexception',
147
                $login,
148
                ['%message%' => $e->getMessage()]
149
            );
150
        }
151
152 1
    }
153
}
154