Completed
Branch develop (9f43d2)
by Filipe
05:14
created

ContainerAwareMethods   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 31
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getContainer() 0 4 1
A setContainer() 0 5 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 Interop\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
0 ignored issues
show
Comprehensibility Bug introduced by
The return type ContainerAwareMethods is a trait, and thus cannot be used for type-hinting in PHP. Maybe consider adding an interface and use that for type-hinting?

In PHP traits cannot be used for type-hinting as they do not define a well-defined structure. This is because any class that uses a trait can rename that trait’s methods.

If you would like to return an object that has a guaranteed set of methods, you could create a companion interface that lists these methods explicitly.

Loading history...
44
     */
45
    public function setContainer(InteropContainer $container)
46
    {
47
        $this->container = $container;
0 ignored issues
show
Documentation Bug introduced by
$container is of type object<Interop\Container\ContainerInterface>, but the property $container was declared to be of type object<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