Passed
Push — master ( dc00b6...0db761 )
by Phillip
02:45
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 LocatorParameterInterface
17
     */
18
    private $parameter;
19
20
    /**
21
     * @var LocatorProxyInterface[]
22
     */
23
    private $proxies;
24
25
    /**
26
     * Locator constructor.
27
     * @param LocatorProxyFactory $factory
28
     */
29 3
    public function __construct(LocatorProxyFactory $factory, LocatorParameterInterface $parameter = null)
30
    {
31 3
        $this->factory = $factory;
32 3
        $this->parameter = $parameter ?? new LocatorParameter();
33 3
        $this->proxies = [];
34 3
    }
35
36
    /**
37
     * @param string $moduleName
38
     * @return LocatorProxyInterface
39
     * @throws Proxy\NotFoundException
40
     */
41 4
    public function locate(string $moduleName) : LocatorProxyInterface
42
    {
43 4
        if(!isset($this->proxies[$moduleName])){
44 3
            $this->proxies[$moduleName] = $this->factory->create($moduleName, $this);
45
        }
46
47 2
        return $this->proxies[$moduleName];
48
    }
49
50
    /**
51
     * @param string $name
52
     * @param array $arguments
53
     * @return LocatorProxyInterface
54
     * @throws Proxy\NotFoundException
55
     */
56 2
    public function __call(string $name, array $arguments)
57
    {
58 2
        return $this->locate(ucfirst($name));
59
    }
60
61
    /**
62
     * @return LocatorParameterInterface
63
     */
64 1
    public function parameter(): LocatorParameterInterface
65
    {
66 1
        return $this->parameter;
67
    }
68
}