ContainerAwareTrait::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
4
namespace DelayQueue\Container;
5
6
7
use DelayQueue\Container\Container;
8
use Psr\Container\ContainerInterface;
9
use Psr\Log\LoggerInterface;
10
use DelayQueue\DelayQueue;
11
12
13
/**
14
 *
15
 * @property LoggerInterface $logger
16
 * @property DelayQueue      $delayQueue
17
 */
18
trait ContainerAwareTrait
19
{
20
    /**
21
     * @var Container
22
     */
23
    protected $container;
24
25
    public function __construct(ContainerInterface $container = null) {
26
        $this->container = $container;
0 ignored issues
show
Documentation Bug introduced by
It seems like $container can also be of type object<Psr\Container\ContainerInterface>. However, the property $container is declared as type object<DelayQueue\Container\Container>. Maybe add an additional type 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 mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
27
    }
28
29
    public function setContainer(ContainerInterface $container)
30
    {
31
        $this->container = $container;
0 ignored issues
show
Documentation Bug introduced by
$container is of type object<Psr\Container\ContainerInterface>, but the property $container was declared to be of type object<DelayQueue\Container\Container>. 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...
32
    }
33
34
35
    public function __get($id)
36
    {
37
        return $this->container->get($id);
38
    }
39
}