Locator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
eloc 20
dl 0
loc 75
c 0
b 0
f 0
ccs 20
cts 20
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getServiceProxy() 0 6 1
A __call() 0 7 2
A getInstance() 0 9 2
A __construct() 0 5 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Xervice\Core\Business\Model\Locator;
5
6
7
use Xervice\Config\Business\XerviceConfig;
8
use Xervice\Core\Business\Model\Locator\Proxy\AbstractLocatorProxy;
9
use Xervice\Core\Business\Model\Locator\Proxy\LocatorProxy;
10
use Xervice\Core\Business\Model\Locator\Proxy\LocatorProxyInterface;
11
use Xervice\Core\CoreConfig;
12
13
class Locator
14
{
15
    /**
16
     * @var \Xervice\Core\Business\Model\Locator\Locator
17
     */
18
    private static $instance;
19
20
    /**
21
     * @var array
22
     */
23
    protected $coreNamespaces;
24
25
    /**
26
     * @var array
27
     */
28
    protected $projectNamespaces;
29
30
    /**
31
     * @var array
32
     */
33
    protected $services;
34
35
    /**
36
     * Locator constructor.
37
     *
38
     * @param array $coreNamespaces
39
     * @param array $projectNamespaces
40
     */
41 1
    public function __construct(array $coreNamespaces, array $projectNamespaces)
42
    {
43 1
        $this->coreNamespaces = $coreNamespaces;
44 1
        $this->projectNamespaces = $projectNamespaces;
45 1
        $this->services = [];
46 1
    }
47
48
    /**
49
     * @return \Generated\Ide\LocatorAutoComplete|\Xervice\Core\Business\Model\Locator\Locator
0 ignored issues
show
Bug introduced by
The type Generated\Ide\LocatorAutoComplete 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...
50
     */
51 10
    public static function getInstance(): Locator
52
    {
53 10
        if (self::$instance === null) {
54 1
            self::$instance = new self(
55 1
                XerviceConfig::get(CoreConfig::CORE_NAMESPACES, ['Xervice']),
56 1
                XerviceConfig::get(CoreConfig::PROJECT_NAMESPACES, ['App'])
57
            );
58
        }
59 10
        return self::$instance;
60
    }
61
62
    /**
63
     * @param string $name
64
     * @param array $arguments
65
     *
66
     * @return \Xervice\Core\Business\Model\Locator\Proxy\LocatorProxyInterface
67
     */
68 9
    public function __call(string $name, array $arguments)
69
    {
70 9
        if (!isset($this->services[$name])) {
71 2
            $this->services[$name] = $this->getServiceProxy($name);
72
        }
73
74 9
        return $this->services[$name];
75
    }
76
77
    /**
78
     * @param string $service
79
     *
80
     * @return \Xervice\Core\Business\Model\Locator\Proxy\AbstractLocatorProxy
81
     */
82 2
    protected function getServiceProxy(string $service): LocatorProxyInterface
83
    {
84 2
        return new LocatorProxy(
85 2
            $this->coreNamespaces,
86 2
            $this->projectNamespaces,
87 2
            ucfirst($service)
88
        );
89
    }
90
}
91