Passed
Pull Request — master (#22)
by Luis
24:40 queued 21:48
created

Edge   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 10
dl 0
loc 50
ccs 18
cts 18
cp 1
rs 10
c 2
b 0
f 0
wmc 9
1
<?php declare(strict_types=1);
2
/**
3
 * PHP version 8.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 properties
18
 */
19
final class Edge implements HasDotRepresentation
20
{
21 15
    public static function inheritance(HasNodeIdentifier $parent, HasNodeIdentifier $child): Edge
22
    {
23 15
        return new Edge($parent, $child, 'dir=back arrowtail=empty style=solid');
24
    }
25
26 13
    public static function implementation(HasNodeIdentifier $interface, HasNodeIdentifier $class): Edge
27
    {
28 13
        return new Edge($interface, $class, 'dir=back arrowtail=empty style=dashed');
29
    }
30
31 16
    public static function association(HasNodeIdentifier $reference, HasNodeIdentifier $class): Edge
32
    {
33 16
        return new Edge($reference, $class, 'dir=back arrowtail=none style=solid');
34
    }
35
36
    /**
37
     * A trait can be used by another trait or a class
38
     */
39 10
    public static function use(HasNodeIdentifier $trait, HasNodeIdentifier $definition): Edge
40
    {
41 10
        return new Edge($trait, $definition, 'dir=back arrowtail=normal style=solid');
42
    }
43
44 29
    private function __construct(
45
        private readonly HasNodeIdentifier $fromNode,
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_STRING, expecting T_VARIABLE on line 45 at column 25
Loading history...
46
        private readonly HasNodeIdentifier $toNode,
47
        private readonly string $options
48
    ) {
49
    }
50
51 17
    public function fromNode(): HasNodeIdentifier
52
    {
53 17
        return $this->fromNode;
54
    }
55
56 17
    public function toNode(): HasNodeIdentifier
57
    {
58 17
        return $this->toNode;
59
    }
60
61 14
    public function options(): string
62
    {
63 14
        return $this->options;
64
    }
65
66 15
    public function dotTemplate(): string
67
    {
68 15
        return 'edge';
69
    }
70
}
71