ServiceLocatorAccess   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 getServiceLocator() 0 6 2
A initServiceLocator() 0 2 1
A setServiceLocator() 0 2 1
1
<?php
2
3
namespace PHPKitchen\DI\Mixins;
4
5
use core\app\Application;
0 ignored issues
show
Bug introduced by
The type core\app\Application was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use yii\di\ServiceLocator;
7
8
/**
9
 * Injects service locator to target class.
10
 * Use this trait only if you can't use dependency injection container.
11
 *
12
 * @property ServiceLocator|\yii\base\Application $serviceLocator public alias of {@link _serviceLocator}
13
 *
14
 * @package PHPKitchen\DI\mixins
15
 * @author Dmitry Kolodko <[email protected]>
16
 */
17
trait ServiceLocatorAccess {
18
    /**
19
     * @var ServiceLocator|\yii\base\Application
20
     */
21
    protected $_serviceLocator;
22
23
    public function getServiceLocator() {
24
        if (!isset($this->_serviceLocator)) {
25
            $this->initServiceLocator();
26
        }
27
28
        return $this->_serviceLocator;
29
    }
30
31
    public function setServiceLocator(ServiceLocator $locator) {
32
        $this->_serviceLocator = $locator;
33
    }
34
35
    protected function initServiceLocator() {
36
        $this->setServiceLocator(\Yii::$app);
37
    }
38
}