Completed
Pull Request — master (#300)
by De Cramer
04:10
created

AbstractConnectionCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 16

Duplication

Lines 19
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 19
loc 19
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 16
nc 1
nop 9
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\AdminGroups\Model\AbstractAdminChatCommand;
7
use eXpansion\Framework\Core\Helpers\ChatNotification;
8
use eXpansion\Framework\Core\Helpers\Time;
9
use eXpansion\Framework\Core\Services\DedicatedConnection\Factory;
10
use eXpansion\Framework\Core\Storage\PlayerStorage;
11
use Maniaplanet\DedicatedServer\Connection;
12
use Maniaplanet\DedicatedServer\Xmlrpc\Exception as DedicatedException;
13
use Psr\Log\LoggerInterface;
14
15
/**
16
 * Class Restart
17
 *
18
 * @package eXpansion\Bundle\AdminChat\ChatCommand;
19
 * @author oliver de Cramer <[email protected]>
20
 */
21
abstract class AbstractConnectionCommand extends AbstractAdminChatCommand
22
{
23
    /** @var Factory */
24
    protected $factory;
25
26
    /** @var ChatNotification */
27
    protected $chatNotification;
28
29
    /** @var PlayerStorage */
30
    protected $playerStorage;
31
32
    /** @var LoggerInterface */
33
    protected $logger;
34
35
    /** @var Time */
36
    protected $timeHelper;
37
38
    /**
39
     * Send chat output to public chat
40
     * @var bool
41
     */
42
    protected $isPublic = true;
43
44
    /**
45
     * AbstractConnectionCommand constructor.
46
     *
47
     * @param $command
48
     * @param $permission
49
     * @param array $aliases
50
     * @param AdminGroups $adminGroupsHelper
51
     * @param Factory $factory
52
     * @param ChatNotification $chatNotification
53
     * @param PlayerStorage $playerStorage
54
     * @param LoggerInterface $logger
55
     * @param Time $timeHelper
56
     */
57 View Code Duplication
    public function __construct(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
58
        $command,
59
        $permission,
60
        array $aliases = [],
61
        AdminGroups $adminGroupsHelper,
62
        Factory $factory,
63
        ChatNotification $chatNotification,
64
        PlayerStorage $playerStorage,
65
        LoggerInterface $logger,
66
        Time $timeHelper
67
    ) {
68
        parent::__construct($command, $permission, $aliases, $adminGroupsHelper);
69
70
        $this->factory = $factory;
71
        $this->chatNotification = $chatNotification;
72
        $this->playerStorage = $playerStorage;
73
        $this->logger = $logger;
74
        $this->timeHelper = $timeHelper;
75
    }
76
77
    /**
78
     * @param bool $bool chat output visibility
79
     */
80
    public function setPublic($bool)
81
    {
82
        $this->isPublic = (bool) $bool;
83
    }
84
85
    /**
86
     * Get admin group Label
87
     *
88
     * @param string $login
89
     * @return string
90
     */
91 View Code Duplication
    public function getGroupLabel($login)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
92
    {
93
        $group = $this->adminGroupsHelper->getLoginUserGroups($login);
94
95
        $groupName = "Admin";
96
        if ($group) {
97
            if ($groupName) {
98
                $groupName = $this->adminGroupsHelper->getGroupLabel($group->getName());
99
            }
100
        }
101
102
        return $groupName;
103
    }
104
105
    /**
106
     * @return bool
107
     */
108
    public function getPublic()
109
    {
110
        return $this->isPublic;
111
    }
112
}
113