Completed
Pull Request — master (#28)
by Tom
16:03
created

AggregateServiceProvider::boot()   A

Complexity

Conditions 3
Paths 3

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 3
eloc 4
nc 3
nop 0
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
    use ContainerAwareTrait;
15
16
    /**
17
     * @var ServiceProviderInterface[]
18
     */
19
    private $providers;
20
21
    /**
22
     * @param ServiceProviderInterface[] $providers
23
     */
24
    public function __construct(array $providers)
25
    {
26
        $this->providers = $providers;
27
28
        $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...
29
            $this->providers,
30
            function (array $provides, ServiceProviderInterface $provider) {
31
                return array_merge($provides, $provider->provides());
32
            },
33
            []
34
        );
35
    }
36
37
    public function setContainer(ContainerInterface $container)
38
    {
39
        parent::setContainer($container);
40
41
        foreach ($this->providers as $provider) {
42
            $provider->setContainer($container);
43
        }
44
    }
45
46
    public function boot()
47
    {
48
        foreach ($this->providers as $provider) {
49
            if ($provider instanceof BootableServiceProviderInterface) {
50
                $provider->boot();
51
            }
52
        }
53
    }
54
55
    public function register()
56
    {
57
        foreach ($this->providers as $provider) {
58
            $provider->register();
59
        }
60
    }
61
}
62