1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Graphp\Graph\Specifics; |
4
|
|
|
|
5
|
|
|
use Graphp\Edge\EdgeInterface; |
6
|
|
|
use Graphp\Edge\EdgeSetFactoryInterface; |
7
|
|
|
use Graphp\Edge\EdgeContainerInterface; |
8
|
|
|
use Graphp\Edge\EdgeSet; |
9
|
|
|
use Graphp\Vertex\VertexInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class UndirectedEdgeContainer |
13
|
|
|
* |
14
|
|
|
* @package Graphp\Graph\Specifics |
15
|
|
|
*/ |
16
|
|
|
final class UndirectedEdgeContainer implements EdgeContainerInterface |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Container vertex edges |
20
|
|
|
* |
21
|
|
|
* @var array |
22
|
|
|
*/ |
23
|
|
|
private $vertexEdges = []; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Construct undirected edge container |
27
|
|
|
* |
28
|
|
|
* @param EdgeSetFactoryInterface $edgeSetFactory - the edge set factory |
29
|
|
|
* @param VertexInterface $vertex - the vertex |
30
|
|
|
*/ |
31
|
6 |
|
public function __construct(EdgeSetFactoryInterface $edgeSetFactory, VertexInterface $vertex) |
32
|
|
|
{ |
33
|
6 |
|
$this->vertexEdges = $edgeSetFactory->createEdgeSet($vertex); |
|
|
|
|
34
|
6 |
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Add an edge to the container |
38
|
|
|
* |
39
|
|
|
* @param EdgeInterface $edge - the edge to be added |
40
|
|
|
*/ |
41
|
5 |
|
public function addEdge(EdgeInterface $edge): void |
42
|
|
|
{ |
43
|
5 |
|
$this->vertexEdges[] = $edge; |
44
|
5 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Remove the edge from the container |
48
|
|
|
* |
49
|
|
|
* @param EdgeInterface $edge - the edge to be removed |
50
|
|
|
*/ |
51
|
1 |
|
public function removeEdge(EdgeInterface $edge): void |
52
|
|
|
{ |
53
|
1 |
|
foreach ($this->vertexEdges as $key => $e) { |
54
|
1 |
|
if ($edge->equals($e)) { |
55
|
1 |
|
unset($this->vertexEdges[$key]); |
56
|
1 |
|
break; |
57
|
|
|
} |
58
|
|
|
} |
59
|
1 |
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Get all container edges |
63
|
|
|
* |
64
|
|
|
* @return EdgeSet |
65
|
|
|
*/ |
66
|
6 |
|
public function getEdges(): EdgeSet |
67
|
|
|
{ |
68
|
6 |
|
return $this->vertexEdges; |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Get the number of edges |
73
|
|
|
* |
74
|
|
|
* @return int |
75
|
|
|
*/ |
76
|
|
|
public function edgeCount(): int |
77
|
|
|
{ |
78
|
|
|
return count($this->vertexEdges); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
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..