Completed
Push — master ( fe8795...c2a002 )
by Luis
04:46 queued 02:28
created

Edge::use()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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;
9
10
/**
11
 * An edge represents 1 of 3 types of relationships between classes and interfaces
12
 *
13
 * 1. Inheritance
14
 * 2. Interface implementation
15
 * 3. Associations
16
 *      - Via constructor injection
17
 *      - Via class attributes
18
 */
19
class Edge implements HasDotRepresentation
20
{
21
    /** @var HasNodeIdentifier */
22
    private $fromNode;
23
24
    /** @var HasNodeIdentifier */
25
    private $toNode;
26
27
    /** @var string */
28
    private $options;
29
30 90
    public function __construct(
31
        HasNodeIdentifier $nodeA,
32
        HasNodeIdentifier $nodeB,
33
        string $options
34
    ) {
35 90
        $this->fromNode = $nodeA;
36 90
        $this->toNode = $nodeB;
37 90
        $this->options = $options;
38 90
    }
39
40 57
    public static function inheritance(HasNodeIdentifier $parent, HasNodeIdentifier $child): Edge
41
    {
42 57
        return new Edge($parent, $child, 'dir=back arrowtail=empty style=solid');
43
    }
44
45 51
    public static function implementation(HasNodeIdentifier $interface, HasNodeIdentifier $class): Edge
46
    {
47 51
        return new Edge($interface, $class, 'dir=back arrowtail=empty style=dashed');
48
    }
49
50 51
    public static function association(HasNodeIdentifier $reference, HasNodeIdentifier $class): Edge
51
    {
52 51
        return new Edge($reference, $class, 'dir=back arrowtail=none style=solid');
53
    }
54
55
    /**
56
     * A trait can be used by another trait or a class
57
     */
58 42
    public static function use(HasNodeIdentifier $trait, HasNodeIdentifier $definition): Edge
59
    {
60 42
        return new Edge($trait, $definition, 'dir=back arrowtail=normal style=solid');
61
    }
62
63 63
    public function fromNode(): HasNodeIdentifier
64
    {
65 63
        return $this->fromNode;
66
    }
67
68 63
    public function toNode(): HasNodeIdentifier
69
    {
70 63
        return $this->toNode;
71
    }
72
73 54
    public function options(): string
74
    {
75 54
        return $this->options;
76
    }
77
78 57
    public function dotTemplate(): string
79
    {
80 57
        return 'edge';
81
    }
82
}
83