Completed
Push — master ( 03d9da...2dac9a )
by Tom
13s
created

ServiceConfig   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 40
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A getKeys() 0 9 1
A getIterator() 0 4 1
1
<?php
2
3
namespace TomPHP\ContainerConfigurator;
4
5
use ArrayIterator;
6
use Assert\Assertion;
7
use InvalidArgumentException;
8
use IteratorAggregate;
9
10
final class ServiceConfig implements IteratorAggregate
11
{
12
    /**
13
     * @var ServiceDefinition[]
14
     */
15
    private $config = [];
16
17
    /**
18
     * @param array $config
19
     * @param bool  $singletonDefault
20
     *
21
     * @throws InvalidArgumentException
22
     */
23
    public function __construct(array $config, $singletonDefault = false)
24
    {
25
        Assertion::boolean($singletonDefault);
26
27
        foreach ($config as $key => $serviceConfig) {
28
            $this->config[] = new ServiceDefinition($key, $serviceConfig, $singletonDefault);
29
        }
30
    }
31
32
    /**
33
     * @return array
34
     */
35
    public function getKeys()
36
    {
37
        return array_map(
38
            function (ServiceDefinition $definition) {
39
                return $definition->getName();
40
            },
41
            $this->config
42
        );
43
    }
44
45
    public function getIterator()
46
    {
47
        return new ArrayIterator($this->config);
48
    }
49
}
50