Passed
Push — master ( 0bd3f5...0b454c )
by Mike
05:30
created

DynamicLocator::getContainer()   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 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
5
namespace Xervice\Core\Locator\Dynamic;
6
7
8
use Core\Locator\Dynamic\ServiceNotParseable;
9
use Xervice\Core\Client\ClientInterface;
10
use Xervice\Core\Dependency\DependencyProviderInterface;
11
use Xervice\Core\Facade\FacadeInterface;
12
use Xervice\Core\Factory\FactoryInterface;
13
use Xervice\Core\Locator\Locator;
14
use Xervice\Core\Locator\Proxy\ProxyInterface;
15
16
trait DynamicLocator
17
{
18
    /**
19
     * @return \Xervice\Core\Factory\FactoryInterface
20
     * @throws \Core\Locator\Dynamic\ServiceNotParseable
21
     */
22 1
    public function getFactory(): FactoryInterface
23
    {
24 1
        return $this->getLocator()->factory();
25
    }
26
27
    /**
28
     * @return \Xervice\Core\Facade\FacadeInterface
29
     * @throws \Core\Locator\Dynamic\ServiceNotParseable
30
     */
31 4
    public function getFacade(): FacadeInterface
32
    {
33 4
        return $this->getLocator()->facade();
34
    }
35
36
    /**
37
     * @return \Xervice\Core\Client\ClientInterface
38
     * @throws \Core\Locator\Dynamic\ServiceNotParseable
39
     */
40 1
    public function getClient(): ClientInterface
41
    {
42 1
        return $this->getLocator()->client();
43
    }
44
45 2
    public function getContainer(): DependencyProviderInterface
46
    {
47 2
        return $this->getLocator()->container();
48
    }
49
50
    /**
51
     * @return \Xervice\Core\Locator\Proxy\ProxyInterface
52
     * @throws \Core\Locator\Dynamic\ServiceNotParseable
53
     */
54 4
    private function getLocator(): ProxyInterface
55
    {
56 4
        return Locator::getInstance()->{$this->getServiceName()}();
57
    }
58
59
    /**
60
     * @return string
61
     * @throws \Core\Locator\Dynamic\ServiceNotParseable
62
     */
63 4
    private function getServiceName(): string
64
    {
65 4
        if (!preg_match('@([A-Za-z]+)\\\\([A-Za-z]+)\\\\([A-Za-z\\\\]+)@', \get_class($this), $matches)) {
66
            throw new ServiceNotParseable(__NAMESPACE__);
67
        }
68
69 4
        return $matches[2];
70
    }
71
}
72