Passed
Push — master ( 6a389c...42f43f )
by Divine Niiquaye
01:03 queued 12s
created

ProviderLoader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 2
b 0
f 0
dl 0
loc 25
ccs 7
cts 7
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A load() 0 4 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of DivineNii opensource projects.
7
 *
8
 * PHP version 7.4 and above required
9
 *
10
 * @author    Divine Niiquaye Ibok <[email protected]>
11
 * @copyright 2021 DivineNii (https://divinenii.com/)
12
 * @license   https://opensource.org/licenses/BSD-3-Clause License
13
 *
14
 * For the full copyright and license information, please view the LICENSE
15
 * file that was distributed with this source code.
16
 */
17
18
namespace Rade\DI\Loader;
19
20
use Rade\DI\{AbstractContainer, Container, ContainerBuilder};
21
use Rade\DI\Services\ServiceProviderInterface;
22
23
/**
24
 * This class delegates container service providers.
25
 * Setting service provider's config, keys should always begin with service provider's class name.
26
 *
27
 * @author Divine Niiquaye Ibok <[email protected]>
28
 */
29
class ProviderLoader
30
{
31
    /** @var ServiceProviderInterface[] */
32
    private array $providers;
33
34
    private array $config;
35
36
    /**
37
     * @param ServiceProviderInterface[] $providers
38
     */
39 2
    public function __construct(array $providers, array $config = [])
40
    {
41 2
        $this->providers = $providers;
42 2
        $this->config = $config;
43 2
    }
44
45
    /**
46
     * Loads service providers will one configuration.
47
     *
48
     * @param Container|ContainerBuilder $container
49
     */
50 2
    public function load(AbstractContainer $container): void
51
    {
52 2
        foreach ($this->providers as $provider) {
53 2
            $container->register($provider, $this->config[\get_class($provider)] ?? []);
54
        }
55 2
    }
56
}
57