InfrastructureFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Assimtech\Tempo\Factory;
4
5
use InvalidArgumentException;
6
use Assimtech\Tempo\Infrastructure;
7
8
/**
9
 * Constructs Infrastructure from configuration
10
 */
11
class InfrastructureFactory
12
{
13
    /**
14
     * @var \Assimtech\Tempo\Factory\NodeFactory $nodeFactory
15
     */
16
    private $nodeFactory;
17
18
    /**
19
     * @var \Assimtech\Tempo\Factory\EnvironmentFactory $envFactory
20
     */
21
    private $envFactory;
22
23
    /**
24
     * @param \Assimtech\Tempo\Factory\NodeFactory $nodeFactory
25
     * @param \Assimtech\Tempo\Factory\EnvironmentFactory $envFactory
26
     */
27 5
    public function __construct(NodeFactory $nodeFactory, EnvironmentFactory $envFactory)
28
    {
29 5
        $this->nodeFactory = $nodeFactory;
30 5
        $this->envFactory = $envFactory;
31 5
    }
32
33
    /**
34
     * @param array|null $config
35
     * @return \Assimtech\Tempo\Infrastructure
36
     * @throws \InvalidArgumentException
37
     */
38 3
    public function create(array $config)
39
    {
40 3
        if (!isset($config['nodes'])) {
41 1
            throw new InvalidArgumentException('config: [nodes] is mandatory');
42
        }
43
44 2
        if (!isset($config['environments'])) {
45 1
            throw new InvalidArgumentException('config: [environments] is mandatory');
46
        }
47
48 1
        $nodes = $this->nodeFactory->create($config['nodes']);
49 1
        $environments = $this->envFactory->create($config['environments'], $nodes);
50
51 1
        $infrastructure = new Infrastructure();
52 1
        $infrastructure->addEnvironments($environments);
53
54 1
        return $infrastructure;
55
    }
56
}
57