File tree Expand file tree Collapse file tree 3 files changed +28
-4
lines changed Expand file tree Collapse file tree 3 files changed +28
-4
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,9 @@ public function isTree()
49
49
catch (UnderflowException $ e ) {
50
50
return false ;
51
51
}
52
+ catch (UnexpectedValueException $ e ) {
53
+ return false ;
54
+ }
52
55
53
56
try {
54
57
$ num = count ($ this ->getVerticesSubtree ($ root ));
@@ -86,6 +89,7 @@ public function getVertexParent(Vertex $vertex)
86
89
*
87
90
* @param Vertex $vertex
88
91
* @return Vertex[]
92
+ * @throws UnexpectedValueException if the given $vertex contains invalid / parallel links (check isTree()!)
89
93
*/
90
94
abstract public function getVerticesChildren (Vertex $ vertex );
91
95
Original file line number Diff line number Diff line change @@ -15,11 +15,21 @@ class InTree extends DirectedTree
15
15
{
16
16
public function getVerticesChildren (Vertex $ vertex )
17
17
{
18
- return $ vertex ->getVerticesEdgeFrom ();
18
+ $ vertices = $ vertex ->getVerticesEdgeFrom ();
19
+ if (count ($ vertices ) !== $ vertex ->getDegreeIn ()) {
20
+ throw new UnexpectedValueException ();
21
+ }
22
+
23
+ return $ vertices ;
19
24
}
20
25
21
26
protected function getVerticesParent (Vertex $ vertex )
22
27
{
23
- return $ vertex ->getVerticesEdgeTo ();
28
+ $ vertices = $ vertex ->getVerticesEdgeTo ();
29
+ if (count ($ vertices ) !== $ vertex ->getDegreeOut ()) {
30
+ throw new UnexpectedValueException ();
31
+ }
32
+
33
+ return $ vertices ;
24
34
}
25
35
}
Original file line number Diff line number Diff line change @@ -16,11 +16,21 @@ class OutTree extends DirectedTree
16
16
{
17
17
public function getVerticesChildren (Vertex $ vertex )
18
18
{
19
- return $ vertex ->getVerticesEdgeTo ();
19
+ $ vertices = $ vertex ->getVerticesEdgeTo ();
20
+ if (count ($ vertices ) !== $ vertex ->getDegreeOut ()) {
21
+ throw new UnexpectedValueException ();
22
+ }
23
+
24
+ return $ vertices ;
20
25
}
21
26
22
27
protected function getVerticesParent (Vertex $ vertex )
23
28
{
24
- return $ vertex ->getVerticesEdgeFrom ();
29
+ $ vertices = $ vertex ->getVerticesEdgeFrom ();
30
+ if (count ($ vertices ) !== $ vertex ->getDegreeIn ()) {
31
+ throw new UnexpectedValueException ();
32
+ }
33
+
34
+ return $ vertices ;
25
35
}
26
36
}
You can’t perform that action at this time.
0 commit comments