FeatureDependencyGraphBuilder   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 56
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B build() 0 24 6
1
<?php
2
namespace PSB\Core\Feature;
3
4
5
use PSB\Core\Util\DependencyGraph\DependencyGraph;
6
use PSB\Core\Util\DependencyGraph\GraphBuilderInterface;
7
8
class FeatureDependencyGraphBuilder implements GraphBuilderInterface
9
{
10
11
    /**
12
     * @var Feature[]
13
     */
14
    private $features;
15
16
    /**
17
     * @var Feature[]
18
     */
19
    private $fqcnToFeature = [];
20
21
    /**
22
     * The actual graph maintained as an array of arrays (node fqcn to successor fqcns).
23
     *
24
     * @var [][]
25
     */
26
    private $fqcnDirectedGraph = [];
27
28
    /**
29
     * @param Feature[] $features
30
     */
31 7
    public function __construct($features)
32
    {
33 7
        $this->features = $features;
34 7
    }
35
36
    /**
37
     * @return DependencyGraph
38
     */
39 6
    public function build()
40
    {
41
        // prepare the directed graph lists and fqcn to feature mapping
42 6
        foreach ($this->features as $feature) {
43 6
            $this->fqcnDirectedGraph[$feature->getName()] = [];
44 6
            $this->fqcnToFeature[$feature->getName()] = $feature;
45
        }
46
47
        // build the actual graph from feature dependencies
48 6
        foreach ($this->features as $feature) {
49 6
            $flattenedDependencies = [];
50 6
            if ($feature->getDependencies()) {
51 3
                $flattenedDependencies = array_unique(call_user_func_array('array_merge', $feature->getDependencies()));
52
            }
53
54 6
            foreach ($flattenedDependencies as $dependency) {
55 3
                if (isset($this->fqcnToFeature[$dependency])) {
56 3
                    $this->fqcnDirectedGraph[$dependency][] = $feature->getName();
57
                }
58
            }
59
        }
60
61 6
        return new DependencyGraph($this->fqcnToFeature, $this->fqcnDirectedGraph);
62
    }
63
}
64