Completed
Push — dev ( 007c56...e65940 )
by
unknown
04:40
created

TimeParameterCommand   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 9

Importance

Changes 0
Metric Value
wmc 9
lcom 2
cbo 9
dl 0
loc 107
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 8 1
A getDescription() 0 4 1
A execute() 0 14 2
A setParameterDescription() 0 4 1
A setDescription() 0 4 1
A setChatMessage() 0 4 1
A setFunctionName() 0 4 1
A validate() 0 6 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\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  Reaby
18
 * @package eXpansion\Bundle\AdminChat\ChatCommand
19
 */
20
class TimeParameterCommand extends AbstractConnectionCommand
21
{
22
    /**
23
     * Description of the parameter
24
     *
25
     * @var string
26
     */
27
    protected $parameterDescription;
28
29
    /**
30
     * Description of the command.
31
     *
32
     * @var string
33
     */
34
    protected $description;
35
36
    /**
37
     * Message to display in chat.
38
     *
39
     * @var string
40
     */
41
    protected $chatMessage;
42
43
    /**
44
     * Name of the dedicated function to call.
45
     *
46
     * @var string
47
     */
48
    protected $functionName;
49
50
    /**
51
     * @inheritdoc
52
     */
53
    protected function configure()
54
    {
55
        parent::configure();
56
57
        $this->inputDefinition->addArgument(
58
            new InputArgument('parameter', InputArgument::REQUIRED, $this->parameterDescription)
59
        );
60
    }
61
62
    /**
63
     * @inheritdoc
64
     */
65
    public function getDescription()
66
    {
67
        return $this->description;
68
    }
69
70
    /**
71
     * @inheritdoc
72
     */
73
    public function execute($login, InputInterface $input)
74
    {
75
        $nickName = $this->playerStorage->getPlayerInfo($login)->getNickName();
76
        $parameter = $this->timeHelper->textToTime($input->getArgument('parameter'));
77
        $group = $this->adminGroupsHelper->getLoginUserGroups($login)->getName();
78
79
        $this->chatNotification->sendMessage(
80
            $this->chatMessage,
81
            $this->isPublic ? null : $login,
82
            ['%adminLevel%' => $group, '%admin%' => $nickName, "%parameter%" => $parameter]
83
        );
84
85
        $this->connection->{$this->functionName}($parameter);
86
    }
87
88
    /**
89
     * @param string $parameterDescription
90
     */
91
    public function setParameterDescription($parameterDescription)
92
    {
93
        $this->parameterDescription = $parameterDescription;
94
    }
95
96
    /**
97
     * @param string $description
98
     */
99
    public function setDescription($description)
100
    {
101
        $this->description = $description;
102
    }
103
104
    /**
105
     * @param string $chatMessage
106
     */
107
    public function setChatMessage($chatMessage)
108
    {
109
        $this->chatMessage = $chatMessage;
110
    }
111
112
    /**
113
     * @param string $functionName
114
     */
115
    public function setFunctionName($functionName)
116
    {
117
        $this->functionName = $functionName;
118
    }
119
120
    public function validate($login, $parameter)
121
    {
122
        print_r($parameter);
123
124
        return parent::validate($login, $parameter); // TODO: Change the autogenerated stub
125
    }
126
}
127