Completed
Pull Request — master (#106)
by De Cramer
03:01
created

AdminCommand::getDescription()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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 Monolog\Logger;
11
use Psr\Log\LoggerInterface;
12
use Symfony\Component\Console\Input\InputArgument;
13
use Symfony\Component\Console\Input\InputInterface;
14
15
/**
16
 * Class ReasonUserCommand
17
 *
18
 * @author  Reaby
19
 * @package eXpansion\Bundle\AdminChat\ChatCommand
20
 */
21
class AdminCommand extends AbstractConnectionCommand
22
{
23
    /**
24
     * Description of the command.
25
     *
26
     * @var string
27
     */
28
    protected $description;
29
30
    /**
31
     * Message to display in chat.
32
     *
33
     * @var string
34
     */
35
    protected $chatMessage;
36
37
    /**
38
     * Name of the dedicated function to call.
39
     *
40
     * @var string
41
     */
42
    protected $functionName;
43
44
    /**
45
     * AdminCommand constructor.
46
     *
47
     * @param $command
48
     * @param string $permission
49
     * @param array $aliases
50
     * @param ChatNotification $functionName
51
     * @param AdminGroups $adminGroupsHelper
52
     * @param Connection $connection
53
     * @param ChatNotification $chatNotification
54
     * @param PlayerStorage $playerStorage
55
     * @param LoggerInterface $logger
56
     * @param Time $timeHelper
57
     */
58 3
    public function __construct(
59
        $command,
60
        $permission,
61
        array $aliases = [],
62
        $functionName,
63
        AdminGroups $adminGroupsHelper,
64
        Connection $connection,
65
        ChatNotification $chatNotification,
66
        PlayerStorage $playerStorage,
67
        LoggerInterface $logger,
68
        Time $timeHelper
69
    ) {
70 3
        parent::__construct(
71 3
            $command,
72 3
            $permission,
73 3
            $aliases,
74 3
            $adminGroupsHelper,
75 3
            $connection,
76 3
            $chatNotification,
77 3
            $playerStorage,
78 3
            $logger,
79 3
            $timeHelper
80
        );
81
82 3
        $this->description = 'expansion_admin_chat.' . strtolower($functionName) . '.description';
83 3
        $this->chatMessage = 'expansion_admin_chat.' . strtolower($functionName) . '.msg';
84 3
        $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...
85 3
    }
86
87
    /**
88
     * @inheritdoc
89
     */
90 1
    public function execute($login, InputInterface $input)
91
    {
92 1
        $nickName = $this->playerStorage->getPlayerInfo($login)->getNickName();
93 1
        $group = $this->getGroupLabel($login);
94
95 1
        $this->chatNotification->sendMessage(
96 1
            $this->chatMessage,
97 1
            $this->isPublic ? null : $login,
98 1
            ['%adminLevel%' => $group, '%admin%' => $nickName]
99
        );
100
101 1
        $this->connection->{$this->functionName}();
102 1
    }
103
}
104