Completed
Branch master (d31b6a)
by Bingo
05:22 queued 01:30
created

DefaultEdge   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 99
Duplicated Lines 0 %

Test Coverage

Coverage 89.47%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
eloc 12
c 1
b 0
f 1
dl 0
loc 99
ccs 17
cts 19
cp 0.8947
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A equals() 0 3 1
A getHash() 0 3 1
A __construct() 0 3 1
A setTarget() 0 3 1
A getTarget() 0 3 1
A setSource() 0 3 1
A __toString() 0 3 1
A getSource() 0 3 1
1
<?php
2
3
namespace graphp\edge;
4
5
use graphp\vertex\VertexInterface;
6
7
/**
8
 * Class DefaultEdge
9
 *
10
 * @package graphp\edge
11
 */
12
class DefaultEdge implements EdgeInterface
13
{
14
    /**
15
     * The edge unique hash
16
     *
17
     * @var string
18
     */
19
    private $hash;
20
21
    /**
22
     * The edge source vertex
23
     *
24
     * @var VertexInterface
25
     */
26
    protected $sourceVertex;
27
    
28
    /**
29
     * The edge target vertex
30
     *
31
     * @var VertexInterface
32
     */
33
    protected $targetVertex;
34
35
    /**
36
     * Construct a new edge
37
     */
38 11
    public function __construct()
39
    {
40 11
        $this->hash = uniqid('', true);
41 11
    }
42
43
    /**
44
     * Check if two edges are equal
45
     *
46
     * @param EdgeInterface $other - other edge to be compared
47
     */
48 5
    public function equals(EdgeInterface $other): bool
49
    {
50 5
        return $this->hash == $other->getHash();
0 ignored issues
show
Bug introduced by
The method getHash() does not exist on graphp\edge\EdgeInterface. Since it exists in all sub-types, consider adding an abstract or default implementation to graphp\edge\EdgeInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

50
        return $this->hash == $other->/** @scrutinizer ignore-call */ getHash();
Loading history...
51
    }
52
53
    /**
54
     * Get the edge hash
55
     *
56
     * @return string
57
     */
58 6
    public function getHash(): string
59
    {
60 6
        return $this->hash;
61
    }
62
    
63
    /**
64
     * Get the edge source vertex
65
     *
66
     * @return VertexInterface
67
     */
68 2
    public function getSource(): VertexInterface
69
    {
70 2
        return $this->sourceVertex;
71
    }
72
    
73
    /**
74
     * Get the edge target vertex
75
     *
76
     * @return VertexInterface
77
     */
78 2
    public function getTarget(): VertexInterface
79
    {
80 2
        return $this->targetVertex;
81
    }
82
83
    /**
84
     * Set the edge source vertex
85
     *
86
     * @param VertexInterface $vertex - the source vertex
87
     */
88 2
    public function setSource(VertexInterface $vertex): void
89
    {
90 2
        $this->sourceVertex = $vertex;
91 2
    }
92
    
93
    /**
94
     * Set the edge target vertex
95
     *
96
     * @param VertexInterface $vertex - the target vertex
97
     */
98 2
    public function setTarget(VertexInterface $vertex): void
99
    {
100 2
        $this->targetVertex = $vertex;
101 2
    }
102
103
    /**
104
     * Get the edge string representation
105
     *
106
     * @return string
107
     */
108
    public function __toString(): string
109
    {
110
        return "(" . $this->sourceVertex + " : " + $this->targetVertex + ")";
0 ignored issues
show
Bug introduced by
Are you sure $this->sourceVertex of type graphp\vertex\VertexInterface can be used in concatenation? Consider adding a __toString()-method. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

110
        return "(" . /** @scrutinizer ignore-type */ $this->sourceVertex + " : " + $this->targetVertex + ")";
Loading history...
111
    }
112
}
113