Passed
Push — master ( 7f6653...1b8b0b )
by Phillip
02:44
created

Locator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
wmc 4
eloc 9
dl 0
loc 45
ccs 6
cts 10
cp 0.6
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __call() 0 3 1
A __construct() 0 4 1
A locate() 0 7 2
1
<?php
2
3
namespace PHPassword\Locator;
4
5
use PHPassword\Locator\Proxy\LocatorProxyFactory;
6
use PHPassword\Locator\Proxy\LocatorProxyInterface;
7
8
class Locator
9
{
10
    /**
11
     * @var LocatorProxyFactory
12
     */
13
    private $factory;
14
15
    /**
16
     * @var LocatorProxyInterface[]
17
     */
18
    private $proxies;
19
20
    /**
21
     * Locator constructor.
22
     * @param LocatorProxyFactory $factory
23
     */
24
    public function __construct(LocatorProxyFactory $factory)
25
    {
26
        $this->factory = $factory;
27
        $this->proxies = [];
28
    }
29
30
    /**
31
     * @param string $moduleName
32
     * @return LocatorProxyInterface
33
     * @throws Proxy\NotFoundException
34
     */
35 4
    public function locate(string $moduleName) : LocatorProxyInterface
36
    {
37 4
        if(!isset($this->proxies[$moduleName])){
38 3
            $this->proxies[$moduleName] = $this->factory->create($moduleName);
39
        }
40
41 2
        return $this->proxies[$moduleName];
42
    }
43
44
    /**
45
     * @param string $name
46
     * @param array $arguments
47
     * @return LocatorProxyInterface
48
     * @throws Proxy\NotFoundException
49
     */
50 2
    public function __call(string $name, array $arguments)
51
    {
52 2
        return $this->locate(ucfirst($name));
53
    }
54
}