Completed
Push — dev ( 066e8b...4c089d )
by De Cramer
08:34
created

ReasonUserCommand::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 28
nc 1
nop 13

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
    protected $parameterLoginDescription;
23
24
    protected $parameterReasonDescription;
25
26
    protected $description;
27
28
    protected $chatMessage;
29
30
    protected $functionName;
31
32
    public function __construct(
33
        $command,
34
        $permission,
35
        array $aliases = [],
36
        AdminGroups $adminGroupsHelper,
37
        Connection $connection,
38
        ChatNotification $chatNotification,
39
        PlayerStorage $playerStorage,
40
        LoggerInterface $logger,
41
        $parameterLoginDescription,
42
        $parameterReasonDescription,
43
        $description,
44
        $chatMessage,
45
        $functionName
46
    ) {
47
        parent::__construct(
48
            $command,
49
            $permission,
50
            $aliases,
51
            $adminGroupsHelper,
52
            $connection,
53
            $chatNotification,
54
            $playerStorage,
55
            $logger
56
        );
57
58
        $this->parameterLoginDescription = $parameterLoginDescription;
59
        $this->parameterReasonDescription = $parameterReasonDescription;
60
        $this->description = $description;
61
        $this->chatMessage = $chatMessage;
62
        $this->functionName = $functionName;
63
    }
64
65
66
    /**
67
     * @inheritdoc
68
     */
69
    protected function configure()
70
    {
71
        parent::configure();
72
73
        $this->inputDefinition->addArgument(
74
            new InputArgument('login', InputArgument::REQUIRED, $this->parameterLoginDescription)
75
        );
76
        $this->inputDefinition->addArgument(
77
            new InputArgument('reason', InputArgument::REQUIRED, $this->parameterReasonDescription)
78
        );
79
    }
80
81
    /**
82
     * @inheritdoc
83
     */
84
    public function getDescription()
85
    {
86
        return $this->description;
87
    }
88
89
    /**
90
     * @inheritdoc
91
     */
92
    public function execute($login, InputInterface $input)
93
    {
94
        $nickName = $this->playerStorage->getPlayerInfo($login)->getNickName();
95
        $playerLogin = $input->getArgument('login');
96
        $reason = $input->getArgument('reason');
97
98
        $playerNickName = $this->playerStorage->getPlayerInfo($playerLogin)->getNickName();
99
100
        $this->chatNotification->sendMessage(
101
            $this->chatMessage,
102
            null,
103
            ['%admin%' => $nickName, '%player%' => $playerNickName, "%reason%" => $reason]
104
        );
105
106
        $this->connection->{$this->functionName}($playerLogin, $reason);
107
    }
108
}
109