InfrastructureFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 46
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A create() 0 18 3
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