Completed
Pull Request — master (#59)
by
unknown
06:25 queued 03:32
created

ReasonUserCommand   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 126
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 9

Test Coverage

Coverage 97.44%

Importance

Changes 0
Metric Value
wmc 10
lcom 2
cbo 9
dl 0
loc 126
ccs 38
cts 39
cp 0.9744
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getDescription() 0 4 1
A setParameterLoginDescription() 0 4 1
A setParameterReasonDescription() 0 4 1
A setDescription() 0 4 1
A setChatMessage() 0 4 1
A setFunctionName() 0 4 1
A configure() 0 11 1
A execute() 0 22 3
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\Storage\PlayerStorage;
8
use Maniaplanet\DedicatedServer\Connection;
9
use Monolog\Logger;
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 Smile
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
     * @inheritdoc
60
     */
61 2
    protected function configure()
62
    {
63 2
        parent::configure();
64
65 2
        $this->inputDefinition->addArgument(
66 2
            new InputArgument('login', InputArgument::REQUIRED, $this->parameterLoginDescription)
67
        );
68 2
        $this->inputDefinition->addArgument(
69 2
            new InputArgument('reason', InputArgument::REQUIRED, $this->parameterReasonDescription)
70
        );
71 2
    }
72
73
    /**
74
     * @inheritdoc
75
     */
76 1
    public function getDescription()
77
    {
78 1
        return $this->description;
79
    }
80
81
    /**
82
     * @inheritdoc
83
     */
84 1
    public function execute($login, InputInterface $input)
85
    {
86 1
        $nickName = $this->playerStorage->getPlayerInfo($login)->getNickName();
87 1
        $playerLogin = $input->getArgument('login');
88 1
        $reason = $input->getArgument('reason');
89 1
        $group = $this->adminGroupsHelper->getLoginUserGroups($login);
90 1
        if ($group) {
91
            $group = $group->getName();
92
        } else {
93 1
            $group = "Admin";
94
        }
95
96 1
        $playerNickName = $this->playerStorage->getPlayerInfo($playerLogin)->getNickName();
97
98 1
        $this->chatNotification->sendMessage(
99 1
            $this->chatMessage,
100 1
            $this->isPublic ? null : $login,
101 1
            ['%adminLevel%' => $group, '%admin%' => $nickName, '%player%' => $playerNickName, "%reason%" => $reason]
102
        );
103
104 1
        $this->connection->{$this->functionName}($playerLogin, $reason);
105 1
    }
106
107
    /**
108
     * @param string $parameterLoginDescription
109
     */
110 2
    public function setParameterLoginDescription($parameterLoginDescription)
111
    {
112 2
        $this->parameterLoginDescription = $parameterLoginDescription;
113 2
    }
114
115
    /**
116
     * @param string $parameterReasonDescription
117
     */
118 2
    public function setParameterReasonDescription($parameterReasonDescription)
119
    {
120 2
        $this->parameterReasonDescription = $parameterReasonDescription;
121 2
    }
122
123
    /**
124
     * @param string $description
125
     */
126 2
    public function setDescription($description)
127
    {
128 2
        $this->description = $description;
129 2
    }
130
131
    /**
132
     * @param string $chatMessage
133
     */
134 2
    public function setChatMessage($chatMessage)
135
    {
136 2
        $this->chatMessage = $chatMessage;
137 2
    }
138
139
    /**
140
     * @param string $functionName
141
     */
142 2
    public function setFunctionName($functionName)
143
    {
144 2
        $this->functionName = $functionName;
145 2
    }
146
}
147