Completed
Push — master ( b54cbd...d09870 )
by Luis
18:59
created

InterfaceGraphBuilder::extractFrom()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * PHP version 7.1
4
 *
5
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
6
 */
7
8
namespace PhUml\Graphviz\Builders;
9
10
use PhUml\Code\InterfaceDefinition;
11
use PhUml\Graphviz\Edge;
12
use PhUml\Graphviz\Node;
13
14
/**
15
 * It produces the collection of nodes and edges related to an interface
16
 *
17
 * It creates a node with the interface itself
18
 * It creates an edge using the interface it extends, if any
19
 */
20
class InterfaceGraphBuilder
21
{
22
    /** @var NodeLabelBuilder */
23
    private $labelBuilder;
24
25
    public function __construct(NodeLabelBuilder $labelBuilder)
26
    {
27
        $this->labelBuilder = $labelBuilder;
28
    }
29
30
    /**
31
     * The order in which the nodes and edges are created is as follows
32
     *
33
     * 1. The node representing the interface itself
34
     * 2. The parent interface, if any
35
     *
36
     * @return \PhUml\Graphviz\HasDotRepresentation[]
37
     */
38
    public function extractFrom(InterfaceDefinition $interface): array
39
    {
40
        $dotElements = [];
41
42
        $dotElements[] = new Node($interface, $this->labelBuilder->forInterface($interface));
43
44
        if ($interface->hasParent()) {
45
            $dotElements[] = Edge::inheritance($interface->extends, $interface);
46
        }
47
48
        return $dotElements;
49
    }
50
}
51