DynamicCommunicationLocator   A
last analyzed

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
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0

4 Methods

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