Completed
Push — dev ( ade326...e1b211 )
by
unknown
03:23
created

AbstractConnectionCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
ccs 8
cts 8
cp 1
cc 1
eloc 16
nc 1
nop 9
crap 1

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\AdminGroups\Model\AbstractAdminChatCommand;
7
use eXpansion\Framework\Core\Helpers\ChatNotification;
8
use eXpansion\Framework\Core\Helpers\Time;
9
use eXpansion\Framework\Core\Storage\PlayerStorage;
10
use Maniaplanet\DedicatedServer\Connection;
11
use Psr\Log\LoggerInterface;
12
13
/**
14
 * Class Restart
15
 *
16
 * @package eXpansion\Bundle\AdminChat\ChatCommand;
17
 * @author oliver de Cramer <[email protected]>
18
 */
19
abstract class AbstractConnectionCommand extends AbstractAdminChatCommand
20
{
21
    /** @var Connection */
22
    protected $connection;
23
24
    /** @var ChatNotification */
25
    protected $chatNotification;
26
27
    /** @var PlayerStorage */
28
    protected $playerStorage;
29
30
    /** @var LoggerInterface */
31
    protected $logger;
32
33
    /** @var Time */
34
    protected $timeHelper;
35
36
    /**
37
     * Send chat output to public chat
38
     * @var bool
39
     */
40
    protected $isPublic = true;
41
42
    /**
43
     * AbstractConnectionCommand constructor.
44
     * @param $command
45
     * @param string $permission
46
     * @param array $aliases
47
     * @param AdminGroups $adminGroupsHelper
48
     * @param Connection $connection
49
     * @param ChatNotification $chatNotification
50
     * @param PlayerStorage $playerStorage
51
     * @param LoggerInterface $logger
52
     * @param Time $timeHelper
53
     */
54 2
    public function __construct(
55
        $command,
56
        $permission,
57
        array $aliases = [],
58
        AdminGroups $adminGroupsHelper,
59
        Connection $connection,
60
        ChatNotification $chatNotification,
61
        PlayerStorage $playerStorage,
62
        LoggerInterface $logger,
63
        Time $timeHelper
64
    ) {
65 2
        parent::__construct($command, $permission, $aliases, $adminGroupsHelper);
66
67 2
        $this->connection = $connection;
68 2
        $this->chatNotification = $chatNotification;
69 2
        $this->playerStorage = $playerStorage;
70 2
        $this->logger = $logger;
71 2
        $this->timeHelper = $timeHelper;
72 2
    }
73
74
    /**
75
     * @param bool $bool chat output visibility
76
     */
77
    public function setPublic($bool)
78
    {
79
        $this->isPublic = (bool)$bool;
80
    }
81
82
    /**
83
     * Get admin group Label
84
     *
85
     * @param string $login
86
     * @return string
87
     */
88 1
    public function getGroupLabel($login)
89
    {
90 1
        $group = $this->adminGroupsHelper->getLoginUserGroups($login);
91
92 1
        $groupName = "Admin";
93 1
        if ($group) {
94
            if ($groupName) {
95
                $groupName = $this->adminGroupsHelper->getGroupLabel($group->getName());
96
97
            }
98
        }
99
100 1
        return $groupName;
101
    }
102
103
}
104