Completed
Pull Request — master (#154)
by De Cramer
02:58
created

ControlCommand::execute()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 28
Code Lines 21

Duplication

Lines 10
Ratio 35.71 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 10
loc 28
rs 8.439
c 0
b 0
f 0
ccs 0
cts 20
cp 0
cc 5
eloc 21
nc 5
nop 2
crap 30
1
<?php
2
3
namespace eXpansion\Bundle\CustomChat\ChatCommand;
4
5
use eXpansion\Bundle\CustomChat\Plugins\CustomChat;
6
use eXpansion\Framework\AdminGroups\Helpers\AdminGroups;
7
use eXpansion\Framework\AdminGroups\Model\AbstractAdminChatCommand;
8
use eXpansion\Framework\Core\Helpers\ChatNotification;
9
use eXpansion\Framework\Core\Storage\PlayerStorage;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputInterface;
12
13
14
/**
15
 * Class BasicEmote to handle basic emote chat oommands.
16
 *
17
 * @package eXpansion\Bundle\Emotes\ChatCommand;
18
 * @author reaby
19
 */
20
class ControlCommand extends AbstractAdminChatCommand
21
{
22
    /** @var string[] */
23
    protected $messages;
24
25
    /** @var ChatNotification */
26
    protected $chatNotification;
27
28
    /**
29
     * @var CustomChat
30
     */
31
    private $customChat;
32
    /**
33
     * @var PlayerStorage
34
     */
35
    private $playerStorage;
36
37
    /**
38
     * BasicEmote constructor.
39
     *
40
     * @param string $command The chat command
41
     * @param $permission
42
     * @param array $aliases
43
     * @param AdminGroups $adminGroups
44
     * @param ChatNotification $chatNotification
45
     * @param PlayerStorage $playerStorage
46
     * @param CustomChat $customChat
47
     */
48
    public function __construct(
49
        $command,
50
        $permission,
51
        array $aliases = [],
52
        AdminGroups $adminGroups,
53
        ChatNotification $chatNotification,
54
        PlayerStorage $playerStorage,
55
        CustomChat $customChat
56
    ) {
57
        parent::__construct($command, $permission, $aliases, $adminGroups);
58
        $this->chatNotification = $chatNotification;
59
        $this->adminGroup = $adminGroups;
60
        $this->customChat = $customChat;
61
        $this->playerStorage = $playerStorage;
62
    }
63
64
    /**
65
     * @inheritdoc
66
     */
67
    protected function configure()
68
    {
69
        parent::configure();
70
71
        $this->inputDefinition->addArgument(
72
            new InputArgument('parameter', InputArgument::REQUIRED, "status")
73
        );
74
    }
75
76
    /**
77
     * @inheritdoc
78
     */
79
    public function execute($login, InputInterface $input)
80
    {
81
        $group = $this->adminGroupsHelper->getLoginUserGroups($login)->getName();
82
        $groupName = $this->adminGroupsHelper->getGroupLabel($group);
83
84
        $nickName = $this->playerStorage->getPlayerInfo($login)->getNickName();
85
86
        $arg = $input->getArgument('parameter');
87
        switch ($arg) {
88
            case "enable":
89 View Code Duplication
            case "on":
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
90
                $this->chatNotification->sendMessage("expansion_customchat.chat.enabled", null,
91
                    ['%admin%' => $groupName, '%nickname%' => $nickName]);
92
                $this->customChat->setStatus(true);
93
                break;
94
            case "disable":
95 View Code Duplication
            case "off":
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
96
                $this->chatNotification->sendMessage("expansion_customchat.chat.disabled", null,
97
                    ['%admin%' => $groupName, '%nickname%' => $nickName]);
98
                $this->customChat->setStatus(false);
99
                break;
100
            default:
101
                $this->chatNotification->sendMessage("expansion_customchat.chat.invalid", null, ['%arg' => $arg]);
102
                break;
103
104
        }
105
106
    }
107
}
108