Completed
Pull Request — master (#165)
by
unknown
03:29
created

AdminCommand   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 6
dl 0
loc 88
ccs 24
cts 28
cp 0.8571
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 28 1
A execute() 0 18 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\Helpers\Time;
8
use eXpansion\Framework\Core\Storage\PlayerStorage;
9
use Maniaplanet\DedicatedServer\Connection;
10
use Maniaplanet\DedicatedServer\Xmlrpc\Exception as DedicatedException;
11
use Psr\Log\LoggerInterface;
12
use Symfony\Component\Console\Input\InputInterface;
13
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
        try {
95 1
            $this->connection->{$this->functionName}();
96 1
            $this->chatNotification->sendMessage(
97 1
                $this->chatMessage,
98 1
                $this->isPublic ? null : $login,
99 1
                ['%adminLevel%' => $group, '%admin%' => $nickName]
100
            );
101
        } catch (DedicatedException $e) {
102
            $this->logger->error("Error on admin command", ["exception" => $e]);
103
            $this->chatNotification->sendMessage("expansion_admin_chat.dedicatedexception", $login,
104
                ["%message%" => $e->getMessage()]);
105
        }
106
107 1
    }
108
}
109