Completed
Push — dev ( 51753e...214409 )
by De Cramer
02:51
created

AbstractConnectionCommand::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 14
nc 1
nop 8
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\Storage\PlayerStorage;
9
use Maniaplanet\DedicatedServer\Connection;
10
use Monolog\Logger;
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 Logger */
31
    protected $logger;
32
33 2
    public function __construct(
34
        $command,
35
        $permission,
36
        array $aliases = [],
37
        AdminGroups $adminGroupsHelper,
38
        Connection $connection,
39
        ChatNotification $chatNotification,
40
        PlayerStorage $playerStorage,
41
        LoggerInterface $logger
42
    )
43
    {
44 2
        parent::__construct($command, $permission, $aliases, $adminGroupsHelper);
45
46 2
        $this->connection = $connection;
47 2
        $this->chatNotification = $chatNotification;
48 2
        $this->playerStorage = $playerStorage;
49 2
        $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...
50 2
    }
51
}
52