Completed
Push — master ( 5e4c69...6bf127 )
by Tom
02:18
created

AggregateServiceProvider::setContainer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
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\ContainerInterface;
9
10
final class AggregateServiceProvider extends AbstractServiceProvider implements
11
    BootableServiceProviderInterface
12
{
13
    /**
14
     * @var ServiceProviderInterface[]
15
     */
16
    private $providers;
17
18
    /**
19
     * @param ServiceProviderInterface[] $providers
20
     */
21
    public function __construct(array $providers)
22
    {
23
        $this->providers = $providers;
24
25
        $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...
26
            $this->providers,
27
            function (array $provides, ServiceProviderInterface $provider) {
28
                return array_merge($provides, $provider->provides());
29
            },
30
            []
31
        );
32
    }
33
34
    public function setContainer(ContainerInterface $container)
35
    {
36
        parent::setContainer($container);
37
38
        foreach ($this->providers as $provider) {
39
            $provider->setContainer($container);
40
        }
41
    }
42
43
    public function boot()
44
    {
45
        foreach ($this->providers as $provider) {
46
            if ($provider instanceof BootableServiceProviderInterface) {
47
                $provider->boot();
48
            }
49
        }
50
    }
51
52
    public function register()
53
    {
54
        foreach ($this->providers as $provider) {
55
            $provider->register();
56
        }
57
    }
58
}
59