AdminVoteCommand::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 28
ccs 0
cts 27
cp 0
rs 9.472
c 0
b 0
f 0
cc 1
nc 1
nop 11
crap 2

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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\Helpers\TMString;
9
use eXpansion\Framework\Core\Services\Application\Dispatcher;
10
use eXpansion\Framework\Core\Services\DedicatedConnection\Factory;
11
use eXpansion\Framework\Core\Storage\PlayerStorage;
12
use Maniaplanet\DedicatedServer\Connection;
13
use Psr\Log\LoggerInterface;
14
use Maniaplanet\DedicatedServer\Xmlrpc\Exception as DedicatedException;
15
use Symfony\Component\Console\Input\InputInterface;
16
17
/**
18
 * Class ReasonUserCommand
19
 *
20
 * @author  Reaby
21
 * @package eXpansion\Bundle\AdminChat\ChatCommand
22
 */
23
class AdminVoteCommand extends AdminCommand
24
{
25
    /**
26
     * @var Dispatcher
27
     */
28
    private $dispatcher;
29
30
    /**
31
     * AdminVoteCommand constructor.
32
     *
33
     * @param $command
34
     * @param $permission
35
     * @param array $aliases
36
     * @param $functionName
37
     * @param AdminGroups $adminGroupsHelper
38
     * @param Factory $factory
39
     * @param ChatNotification $chatNotification
40
     * @param PlayerStorage $playerStorage
41
     * @param LoggerInterface $logger
42
     * @param Time $timeHelper
43
     * @param Dispatcher $dispatcher
44
     */
45
    public function __construct(
46
        $command,
47
        $permission,
48
        array $aliases = [],
49
        $functionName,
50
        AdminGroups $adminGroupsHelper,
51
        Factory $factory,
52
        ChatNotification $chatNotification,
53
        PlayerStorage $playerStorage,
54
        LoggerInterface $logger,
55
        Time $timeHelper,
56
        Dispatcher $dispatcher
57
    ) {
58
        parent::__construct(
59
            $command,
60
            $permission,
61
            $aliases = [],
62
            $functionName,
63
            $adminGroupsHelper,
64
            $factory,
65
            $chatNotification,
66
            $playerStorage,
67
            $logger,
68
            $timeHelper
69
        );
70
71
        $this->dispatcher = $dispatcher;
72
    }
73
74
    /**
75
     * @inheritdoc
76
     */
77
    public function execute($login, InputInterface $input)
78
    {
79
        parent::execute($login, $input);
80
        $player = $this->playerStorage->getPlayerInfo($login);
81
        $this->dispatcher->dispatch("votemanager.votecancelled", [$player, null, null]);
82
83
        $level = $this->adminGroupsHelper->getLoginGroupLabel($login);
84
        $admin = $player->getNickName();
85
86
        $logMessage = $this->chatNotification->getMessage('%adminLevel% %admin% cancels current vote.',
87
            ["%adminLevel%" => $level, "%admin%" => $admin]);
88
        $this->logger->info("[".$login."] ".TMString::trimStyles($logMessage));
89
    }
90
}
91