ServiceProvider   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
eloc 13
dl 0
loc 56
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 3 1
A get() 0 3 1
A boot() 0 5 3
A execute() 0 5 3
A __construct() 0 6 2
1
<?php
2
3
4
namespace Xervice\Kernel\Business\Model\Service;
5
6
7
8
use Xervice\Kernel\Business\Plugin\BootInterface;
9
use Xervice\Kernel\Business\Plugin\ClearServiceInterface;
10
use Xervice\Kernel\Business\Plugin\ExecuteInterface;
11
12
class ServiceProvider implements ServiceProviderInterface
13
{
14
    /**
15
     * @var \Xervice\Kernel\Business\Model\Service\ServiceInterface[]
16
     */
17
    private $serviceCollection;
18
19
    /**
20
     * ServiceProvider constructor.
21
     *
22
     * @param array $serviceCollection
23
     */
24 1
    public function __construct(array $serviceCollection)
25
    {
26 1
        $this->serviceCollection = [];
27
28 1
        foreach ($serviceCollection as $name => $service) {
29 1
            $this->set($name, new $service());
30
        }
31 1
    }
32
33 1
    public function boot(): void
34
    {
35 1
        foreach ($this->serviceCollection as $service) {
36 1
            if ($service instanceof BootInterface) {
37 1
                $service->boot($this);
38
            }
39
        }
40 1
    }
41
42 1
    public function execute(): void
43
    {
44 1
        foreach ($this->serviceCollection as $service) {
45 1
            if ($service instanceof ExecuteInterface) {
46 1
                $service->execute($this);
47
            }
48
        }
49 1
    }
50
51
    /**
52
     * @param string $serviceName
53
     *
54
     * @return null|\Xervice\Kernel\Business\Plugin\ClearServiceInterface
55
     */
56 1
    public function get(string $serviceName): ?ClearServiceInterface
57
    {
58 1
        return $this->serviceCollection[$serviceName] ?? null;
59
    }
60
61
    /**
62
     * @param string $serviceName
63
     * @param \Xervice\Kernel\Business\Plugin\ClearServiceInterface $service
64
     */
65 1
    public function set(string $serviceName, ClearServiceInterface $service): void
66
    {
67 1
        $this->serviceCollection[$serviceName] = $service;
68
    }
69
}