ContainerAccess   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getContainer() 0 6 2
A setContainer() 0 2 1
A initContainer() 0 2 1
1
<?php
2
3
namespace PHPKitchen\DI\Mixins;
4
5
use PHPKitchen\DI\Contracts\Container;
6
7
/**
8
 * Injects DI container to target class.
9
 *
10
 * @property Container $container public alias of {@link _diContainer}
11
 *
12
 * @package PHPKitchen\DI\mixins
13
 * @author Dmitry Kolodko <[email protected]>
14
 */
15
trait ContainerAccess {
16
    /**
17
     * @var Container
18
     */
19
    protected $_container;
20
21
    public function getContainer() {
22
        if (!isset($this->_container)) {
23
            $this->initContainer();
24
        }
25
26
        return $this->_container;
27
    }
28
29
    public function setContainer(Container $container) {
30
        $this->_container = $container;
31
    }
32
33
    protected function initContainer() {
34
        $this->setContainer(\Yii::$container);
0 ignored issues
show
Bug introduced by
Yii::container of type yii\di\Container is incompatible with the type PHPKitchen\DI\Contracts\Container expected by parameter $container of PHPKitchen\DI\Mixins\Con...rAccess::setContainer(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

34
        $this->setContainer(/** @scrutinizer ignore-type */ \Yii::$container);
Loading history...
35
    }
36
}