Completed
Push — master ( c8e320...41a25f )
by Mike
03:33
created

DynamicLocator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 4
eloc 6
dl 0
loc 29
c 0
b 0
f 0
ccs 7
cts 8
cp 0.875
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getFacade() 0 3 1
A getLocator() 0 3 1
A getServiceName() 0 7 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Xervice\Core\Business\Model\Locator\Dynamic;
5
6
7
use Xervice\Core\Business\Exception\ServiceNotFoundException;
8
use Xervice\Core\Business\Model\Facade\FacadeInterface;
9
use Xervice\Core\Business\Model\Locator\Locator;
10
use Xervice\Core\Business\Model\Locator\Proxy\LocatorProxy;
11
12
trait DynamicLocator
13
{
14
    /**
15
     * @return \Xervice\Core\Business\Model\Facade\FacadeInterface
16
     */
17 1
    public function getFacade(): FacadeInterface
18
    {
19 1
        return $this->getLocator()->facade();
20
    }
21
22
    /**
23
     * @return \Xervice\Core\Business\Model\Locator\Proxy\LocatorProxy
24
     */
25 1
    protected function getLocator(): LocatorProxy
26
    {
27 1
        return Locator::getInstance()->{$this->getServiceName()}();
28
    }
29
30
    /**
31
     * @return string
32
     * @throws \Xervice\Core\Business\Exception\ServiceNotFoundException
33
     */
34 1
    protected function getServiceName(): string
35
    {
36 1
        if (!preg_match('@([A-Za-z]+)\\\\([A-Za-z]+)\\\\([A-Za-z\\\\]+)@', \get_class($this), $matches)) {
37
            throw new ServiceNotFoundException(__NAMESPACE__);
38
        }
39
40 1
        return $matches[2];
41
    }
42
}