Completed
Pull Request — master (#59)
by De Cramer
11:58 queued 07:04
created

ReasonUserCommand::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
crap 1
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 2
    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 2
        parent::__construct(
48 2
            $command,
49 2
            $permission,
50 2
            $aliases,
51 2
            $adminGroupsHelper,
52 2
            $connection,
53 2
            $chatNotification,
54 2
            $playerStorage,
55 2
            $logger
56
        );
57
58 2
        $this->parameterLoginDescription = $parameterLoginDescription;
59 2
        $this->parameterReasonDescription = $parameterReasonDescription;
60 2
        $this->description = $description;
61 2
        $this->chatMessage = $chatMessage;
62 2
        $this->functionName = $functionName;
63 2
    }
64
65
66
    /**
67
     * @inheritdoc
68
     */
69 2
    protected function configure()
70
    {
71 2
        parent::configure();
72
73 2
        $this->inputDefinition->addArgument(
74 2
            new InputArgument('login', InputArgument::REQUIRED, $this->parameterLoginDescription)
75
        );
76 2
        $this->inputDefinition->addArgument(
77 2
            new InputArgument('reason', InputArgument::REQUIRED, $this->parameterReasonDescription)
78
        );
79 2
    }
80
81
    /**
82
     * @inheritdoc
83
     */
84 1
    public function getDescription()
85
    {
86 1
        return $this->description;
87
    }
88
89
    /**
90
     * @inheritdoc
91
     */
92 1
    public function execute($login, InputInterface $input)
93
    {
94 1
        $nickName = $this->playerStorage->getPlayerInfo($login)->getNickName();
95 1
        $playerLogin = $input->getArgument('login');
96 1
        $reason = $input->getArgument('reason');
97
98 1
        $playerNickName = $this->playerStorage->getPlayerInfo($playerLogin)->getNickName();
99
100 1
        $this->chatNotification->sendMessage(
101 1
            $this->chatMessage,
102 1
            null,
103 1
            ['%admin%' => $nickName, '%player%' => $playerNickName, "%reason%" => $reason]
104
        );
105
106 1
        $this->connection->{$this->functionName}($playerLogin, $reason);
107 1
    }
108
}
109