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

Locator::__call()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
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
}