Completed
Push — dev ( 007c56...e65940 )
by
unknown
04:40
created

AbstractConnectionCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 0
cts 0
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\Storage\PlayerStorage;
10
use Maniaplanet\DedicatedServer\Connection;
11
use Monolog\Logger;
12
use Psr\Log\LoggerInterface;
13
14
/**
15
 * Class Restart
16
 *
17
 * @package eXpansion\Bundle\AdminChat\ChatCommand;
18
 * @author oliver de Cramer <[email protected]>
19
 */
20
abstract class AbstractConnectionCommand extends AbstractAdminChatCommand
21
{
22
    /** @var Connection */
23
    protected $connection;
24
25
    /** @var ChatNotification */
26
    protected $chatNotification;
27
28
    /** @var PlayerStorage */
29
    protected $playerStorage;
30
31
    /** @var Logger */
32
    protected $logger;
33 2
34
    /** @var Time */
35
    protected $timeHelper;
36
37
    /**
38
     * Send chat output to public chat
39
     * @var bool
40
     */
41
    protected $isPublic = true;
42
43
    /**
44 2
     * AbstractConnectionCommand constructor.
45
     * @param $command
46 2
     * @param string $permission
47 2
     * @param array $aliases
48 2
     * @param AdminGroups $adminGroupsHelper
49 2
     * @param Connection $connection
50 2
     * @param ChatNotification $chatNotification
51
     * @param PlayerStorage $playerStorage
52
     * @param LoggerInterface $logger
53
     * @param Time $timeHelper
54
     */
55
    public function __construct(
56
        $command,
57
        $permission,
58
        array $aliases = [],
59
        AdminGroups $adminGroupsHelper,
60
        Connection $connection,
61
        ChatNotification $chatNotification,
62
        PlayerStorage $playerStorage,
63
        LoggerInterface $logger,
64
        Time $timeHelper
65
    ) {
66
        parent::__construct($command, $permission, $aliases, $adminGroupsHelper);
67
68
        $this->connection = $connection;
69
        $this->chatNotification = $chatNotification;
70
        $this->playerStorage = $playerStorage;
71
        $this->logger = $logger;
0 ignored issues
show
Documentation Bug introduced by
$logger is of type object<Psr\Log\LoggerInterface>, but the property $logger was declared to be of type object<Monolog\Logger>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
72
        $this->timeHelper = $timeHelper;
73
    }
74
75
    /**
76
     * @param bool $bool chat output visibility
77
     */
78
    public function setPublic($bool)
79
    {
80
        $this->isPublic = (bool)$bool;
81
    }
82
83
}
84