1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace graphp\graph\specifics; |
4
|
|
|
|
5
|
|
|
use graphp\edge\EdgeInterface; |
6
|
|
|
use graphp\edge\EdgeContainerInterface; |
7
|
|
|
use graphp\edge\EdgeSetFactoryInterface; |
8
|
|
|
use graphp\edge\EdgeSet; |
9
|
|
|
use graphp\vertex\VertexInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class DirectedEdgeContainer |
13
|
|
|
* |
14
|
|
|
* @package graphp\graph\specifics |
15
|
|
|
*/ |
16
|
|
|
class DirectedEdgeContainer implements EdgeContainerInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Outgoing vertex edges |
20
|
|
|
* |
21
|
|
|
* @var array |
22
|
|
|
*/ |
23
|
|
|
private $outgoing; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Incoming vertex edges |
27
|
|
|
* |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
private $incoming; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Construct directed edge container |
34
|
|
|
* |
35
|
|
|
* @param EdgeSetFactoryInterface $edgeSetFactory - the edge set factory |
36
|
|
|
* @param VertexInterface $vertex - the vertex |
37
|
|
|
*/ |
38
|
4 |
|
public function __construct(EdgeSetFactoryInterface $edgeSetFactory, VertexInterface $vertex) |
39
|
|
|
{ |
40
|
4 |
|
$this->outgoing = $edgeSetFactory->createEdgeSet($vertex); |
|
|
|
|
41
|
4 |
|
$this->incoming = $edgeSetFactory->createEdgeSet($vertex); |
|
|
|
|
42
|
4 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Get container outgoing edges |
46
|
|
|
* |
47
|
|
|
* @return EdgeSet |
48
|
|
|
*/ |
49
|
2 |
|
public function getOutgoing(): EdgeSet |
50
|
|
|
{ |
51
|
2 |
|
return $this->outgoing; |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Get container incoming edges |
56
|
|
|
* |
57
|
|
|
* @return EdgeSet |
58
|
|
|
*/ |
59
|
2 |
|
public function getIncoming(): EdgeSet |
60
|
|
|
{ |
61
|
2 |
|
return $this->incoming; |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Add the outgoing edge |
66
|
|
|
* |
67
|
|
|
* @param EdgeInterface $edge - the edge to be added |
68
|
|
|
*/ |
69
|
2 |
|
public function addOutgoingEdge(EdgeInterface $edge): void |
70
|
|
|
{ |
71
|
2 |
|
$this->outgoing[] = $edge; |
72
|
2 |
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Add the incoming edge |
76
|
|
|
* |
77
|
|
|
* @param EdgeInterface $edge - the edge to be added |
78
|
|
|
*/ |
79
|
2 |
|
public function addIncomingEdge(EdgeInterface $edge): void |
80
|
|
|
{ |
81
|
2 |
|
$this->incoming[] = $edge; |
82
|
2 |
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Remove outgoing edge |
86
|
|
|
* |
87
|
|
|
* @param EdgeInterface $edge - the edge to be removed |
88
|
|
|
*/ |
89
|
1 |
|
public function removeOutgoingEdge(EdgeInterface $edge): void |
90
|
|
|
{ |
91
|
1 |
|
foreach ($this->outgoing as $key => $e) { |
92
|
1 |
|
if ($edge->equals($e)) { |
93
|
1 |
|
unset($this->outgoing[$key]); |
94
|
1 |
|
break; |
95
|
|
|
} |
96
|
|
|
} |
97
|
1 |
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Remove incoming edge |
101
|
|
|
* |
102
|
|
|
* @param EdgeInterface $edge - the edge to be removed |
103
|
|
|
*/ |
104
|
1 |
|
public function removeIncomingEdge(EdgeInterface $edge): void |
105
|
|
|
{ |
106
|
1 |
|
foreach ($this->incoming as $key => $e) { |
107
|
1 |
|
if ($edge->equals($e)) { |
108
|
1 |
|
unset($this->incoming[$key]); |
109
|
1 |
|
break; |
110
|
|
|
} |
111
|
|
|
} |
112
|
1 |
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Get the number of edges |
116
|
|
|
* |
117
|
|
|
* @return int |
118
|
|
|
*/ |
119
|
|
|
public function edgeCount(): int |
120
|
|
|
{ |
121
|
|
|
return count($this->outgoing) + count($this->incoming); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..