Passed
Pull Request — master (#30)
by
unknown
46:28 queued 21:27
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 declare(strict_types=1);
2
/**
3
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
4
 */
5
6
namespace PhUml\Graphviz;
7
8
/**
9
 * An edge represents 1 of 3 types of relationships between classes and interfaces
10
 *
11
 * 1. Inheritance
12
 * 2. Interface implementation
13
 * 3. Associations
14
 *      - Via constructor injection
15
 *      - Via class properties
16
 */
17
final class Edge implements HasDotRepresentation
18
{
19 15
    public static function inheritance(HasNodeIdentifier $parent, HasNodeIdentifier $child): Edge
20
    {
21 15
        return new Edge($parent, $child, 'dir=back arrowtail=empty style=solid');
22
    }
23
24 13
    public static function implementation(HasNodeIdentifier $interface, HasNodeIdentifier $class): Edge
25
    {
26 13
        return new Edge($interface, $class, 'dir=back arrowtail=empty style=dashed');
27
    }
28
29 16
    public static function association(HasNodeIdentifier $reference, HasNodeIdentifier $class): Edge
30
    {
31 16
        return new Edge($reference, $class, 'dir=back arrowtail=none style=solid');
32
    }
33
34
    /**
35
     * A trait can be used by another trait or a class
36
     */
37 10
    public static function use(HasNodeIdentifier $trait, HasNodeIdentifier $definition): Edge
38
    {
39 10
        return new Edge($trait, $definition, 'dir=back arrowtail=normal style=solid');
40
    }
41
42 29
    private function __construct(
43
        private readonly HasNodeIdentifier $fromNode,
44
        private readonly HasNodeIdentifier $toNode,
45
        private readonly string $options
46
    ) {
47
    }
48
49 17
    public function fromNode(): HasNodeIdentifier
50
    {
51 17
        return $this->fromNode;
52
    }
53
54 17
    public function toNode(): HasNodeIdentifier
55
    {
56 17
        return $this->toNode;
57
    }
58
59 14
    public function options(): string
60
    {
61 14
        return $this->options;
62
    }
63
64 15
    public function dotTemplate(): string
65
    {
66 15
        return 'edge';
67
    }
68
}
69