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

AbstractConnectionCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 92
Duplicated Lines 35.87 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 0
dl 33
loc 92
ccs 0
cts 20
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 19 19 1
A setPublic() 0 4 1
A getGroupLabel() 13 13 3
A getPublic() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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