LocatorProxyFactory::create()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 9
c 0
b 0
f 0
ccs 6
cts 6
cp 1
rs 10
cc 3
nc 2
nop 2
crap 3
1
<?php
2
3
namespace PHPassword\Locator\Proxy;
4
5
use PHPassword\Locator\Facade\EmptyFacade;
6
use PHPassword\Locator\Factory\EmptyFactory;
7
use PHPassword\Locator\Locator;
8
9
class LocatorProxyFactory
10
{
11
    /**
12
     * @var \ArrayObject
13
     */
14
    private $searchableNamespaces;
15
16
    /**
17
     * LocatorProxyFactory constructor.
18
     * @param \ArrayObject $searchableNamespaces
19
     */
20 3
    public function __construct(\ArrayObject $searchableNamespaces)
21
    {
22 3
        $this->searchableNamespaces = $searchableNamespaces;
23 3
    }
24
25
    /**
26
     * @param string $moduleName
27
     * @param Locator $locator
28
     * @return LocatorProxyInterface
29
     * @throws NotFoundException
30
     */
31 5
    public function create(string $moduleName, Locator $locator) : LocatorProxyInterface
32
    {
33 5
        $proxy = new LocatorProxy($this->searchableNamespaces, $moduleName, $locator);
34 5
        if(get_class($proxy->factory()) === EmptyFactory::class
35 5
            && get_class($proxy->facade()) === EmptyFacade::class){
36 3
            throw new NotFoundException(sprintf('Module %s was not found. You need at least a factory or a facade', $moduleName));
37
        }
38
39 2
        return $proxy;
40
    }
41
}