Completed
Pull Request — master (#28)
by Tom
27:09
created

AggregateServiceProvider   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 8
c 2
b 0
f 1
lcom 1
cbo 3
dl 0
loc 49
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A setContainer() 0 8 2
A boot() 0 8 3
A register() 0 6 2
1
<?php
2
3
namespace TomPHP\ConfigServiceProvider\League;
4
5
use League\Container\ServiceProvider\AbstractServiceProvider;
6
use League\Container\ServiceProvider\BootableServiceProviderInterface;
7
use League\Container\ServiceProvider\ServiceProviderInterface;
8
use League\Container\ContainerAwareTrait;
9
use League\Container\ContainerInterface;
10
11
final class AggregateServiceProvider extends AbstractServiceProvider implements
12
    BootableServiceProviderInterface
13
{
14
    /**
15
     * @var ServiceProviderInterface[]
16
     */
17
    private $providers;
18
19
    /**
20
     * @param ServiceProviderInterface[] $providers
21
     */
22
    public function __construct(array $providers)
23
    {
24
        $this->providers = $providers;
25
26
        $this->provides = array_reduce(
0 ignored issues
show
Documentation Bug introduced by
It seems like array_reduce($this->prov...rovides()); }, array()) of type * is incompatible with the declared type array of property $provides.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
27
            $this->providers,
28
            function (array $provides, ServiceProviderInterface $provider) {
29
                return array_merge($provides, $provider->provides());
30
            },
31
            []
32
        );
33
    }
34
35
    public function setContainer(ContainerInterface $container)
36
    {
37
        parent::setContainer($container);
38
39
        foreach ($this->providers as $provider) {
40
            $provider->setContainer($container);
41
        }
42
    }
43
44
    public function boot()
45
    {
46
        foreach ($this->providers as $provider) {
47
            if ($provider instanceof BootableServiceProviderInterface) {
48
                $provider->boot();
49
            }
50
        }
51
    }
52
53
    public function register()
54
    {
55
        foreach ($this->providers as $provider) {
56
            $provider->register();
57
        }
58
    }
59
}
60