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

DynamicBusinessLocator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 5
eloc 7
dl 0
loc 37
c 0
b 0
f 0
ccs 9
cts 10
cp 0.9
rs 10

4 Methods

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