ServiceConfig::getIterator()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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