Completed
Push — dev ( 8e757d...007c56 )
by De Cramer
02:45
created

ReasonUserCommand::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 32
ccs 16
cts 16
cp 1
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 28
nc 1
nop 13
crap 1

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace eXpansion\Bundle\AdminChat\ChatCommand;
4
use eXpansion\Framework\AdminGroups\Helpers\AdminGroups;
5
use eXpansion\Framework\Core\Helpers\ChatNotification;
6
use eXpansion\Framework\Core\Storage\PlayerStorage;
7
use Maniaplanet\DedicatedServer\Connection;
8
use Monolog\Logger;
9
use Psr\Log\LoggerInterface;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputInterface;
12
13
/**
14
 * Class ReasonUserCommand
15
 *
16
 * @author    de Cramer Oliver<[email protected]>
17
 * @copyright 2017 Smile
18
 * @package eXpansion\Bundle\AdminChat\ChatCommand
19
 */
20
class ReasonUserCommand extends AbstractConnectionCommand
21
{
22
    /**
23
     * Description of the login parameter
24
     *
25
     * @var string
26
     */
27
    protected $parameterLoginDescription;
28
29
    /**
30
     * Description of the reason parameter.
31
     *
32
     * @var string
33
     */
34
    protected $parameterReasonDescription;
35
36
    /**
37
     * Description of the command.
38
     *
39
     * @var string
40
     */
41
    protected $description;
42
43
    /**
44
     * Message to display in chat.
45
     *
46
     * @var string
47
     */
48
    protected $chatMessage;
49
50
    /**
51
     * Name of the dedicated function to call.
52
     *
53
     * @var string
54
     */
55
    protected $functionName;
56
57
    /**
58
     * @inheritdoc
59
     */
60 2
    protected function configure()
61
    {
62 2
        parent::configure();
63
64 2
        $this->inputDefinition->addArgument(
65 2
            new InputArgument('login', InputArgument::REQUIRED, $this->parameterLoginDescription)
66
        );
67 2
        $this->inputDefinition->addArgument(
68 2
            new InputArgument('reason', InputArgument::REQUIRED, $this->parameterReasonDescription)
69
        );
70 2
    }
71
72
    /**
73
     * @inheritdoc
74
     */
75 1
    public function getDescription()
76
    {
77 1
        return $this->description;
78
    }
79
80
    /**
81
     * @inheritdoc
82
     */
83 1
    public function execute($login, InputInterface $input)
84
    {
85 1
        $nickName = $this->playerStorage->getPlayerInfo($login)->getNickName();
86 1
        $playerLogin = $input->getArgument('login');
87 1
        $reason = $input->getArgument('reason');
88
89 1
        $playerNickName = $this->playerStorage->getPlayerInfo($playerLogin)->getNickName();
90
91 1
        $this->chatNotification->sendMessage(
92 1
            $this->chatMessage,
93 1
            null,
94 1
            ['%admin%' => $nickName, '%player%' => $playerNickName, "%reason%" => $reason]
95
        );
96
97 1
        $this->connection->{$this->functionName}($playerLogin, $reason);
98 1
    }
99
100
    /**
101
     * @param string $parameterLoginDescription
102
     */
103 2
    public function setParameterLoginDescription($parameterLoginDescription)
104
    {
105 2
        $this->parameterLoginDescription = $parameterLoginDescription;
106 2
    }
107
108
    /**
109
     * @param string $parameterReasonDescription
110
     */
111 2
    public function setParameterReasonDescription($parameterReasonDescription)
112
    {
113 2
        $this->parameterReasonDescription = $parameterReasonDescription;
114 2
    }
115
116
    /**
117
     * @param string $description
118
     */
119 2
    public function setDescription($description)
120
    {
121 2
        $this->description = $description;
122 2
    }
123
124
    /**
125
     * @param string $chatMessage
126
     */
127 2
    public function setChatMessage($chatMessage)
128
    {
129 2
        $this->chatMessage = $chatMessage;
130 2
    }
131
132
    /**
133
     * @param string $functionName
134
     */
135 2
    public function setFunctionName($functionName)
136
    {
137 2
        $this->functionName = $functionName;
138 2
    }
139
}
140