Passed
Branch feature/code-quality (2bf2a5)
by Filipe
13:16
created

ContainerAwareMethods   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 29
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getContainer() 0 3 1
A setContainer() 0 4 1
1
<?php
2
3
/**
4
 * This file is part of slick/di
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Slick\Di;
11
12
use Psr\Container\ContainerInterface as InteropContainer;
13
14
/**
15
 * Implementation methods for ContainerAwareInterface
16
 *
17
 * @package Slick\Di
18
 * @author  Filipe Silva <[email protected]>
19
 */
20
trait ContainerAwareMethods
21
{
22
23
    /**
24
     * @var ContainerInterface
25
     */
26
    protected $container;
27
28
    /**
29
     * Get container
30
     *
31
     * @return InteropContainer
32
     */
33
    public function getContainer()
34
    {
35
        return $this->container;
36
    }
37
38
    /**
39
     * Set container
40
     *
41
     * @param InteropContainer $container
42
     *
43
     * @return self|$this|ContainerAwareMethods
44
     */
45
    public function setContainer(InteropContainer $container)
46
    {
47
        $this->container = $container;
0 ignored issues
show
Documentation Bug introduced by
$container is of type Psr\Container\ContainerInterface, but the property $container was declared to be of type Slick\Di\ContainerInterface. 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...
48
        return $this;
49
    }
50
}
51