Skip to content

Commit fdafb56

Browse files
author
Christian Lück
committed
Rename isDirected() to hasDirected() and add hasUndirected(), isMixed()
1 parent e6458fa commit fdafb56

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

src/Directed.php

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Fhaculty\Graph\Algorithm\BaseGraph;
66
use Fhaculty\Graph\Edge\Directed as EdgeDirected;
7+
use Fhaculty\Graph\Edge\Undirected as EdgeUndirected;
78

89
/**
910
* Basic algorithms for working with the undirected or directed Graphs (digraphs) / Walks.
@@ -14,11 +15,14 @@
1415
class Directed extends BaseDual
1516
{
1617
/**
17-
* checks whether the graph has any directed edges (aka digraph)
18+
* checks whether the graph has any directed edges
19+
*
20+
* This method is intentionally not named "isDirected()" (aka digraph),
21+
* because that might be misleading in regards to empty and/or mixed graphs.
1822
*
1923
* @return boolean
2024
*/
21-
public function isDirected()
25+
public function hasDirected()
2226
{
2327
foreach ($this->set->getEdges() as $edge) {
2428
if ($edge instanceof EdgeDirected) {
@@ -28,4 +32,35 @@ public function isDirected()
2832

2933
return false;
3034
}
35+
36+
/**
37+
* checks whether the graph has any undirected edges
38+
*
39+
* This method is intentionally not named "isUndirected()",
40+
* because that might be misleading in regards to empty and/or mixed graphs.
41+
*
42+
* @return boolean
43+
*/
44+
public function hasUndirected()
45+
{
46+
foreach ($this->set->getEdges() as $edge) {
47+
if ($edge instanceof EdgeUndirected) {
48+
return true;
49+
}
50+
}
51+
52+
return false;
53+
}
54+
55+
/**
56+
* checks whether this is a mixed graph (contains both directed and undirected edges)
57+
*
58+
* @return boolean
59+
* @uses self::hasDirected()
60+
* @uses self::hasUndirected()
61+
*/
62+
public function isMixed()
63+
{
64+
return ($this->hasDirected() && $this->hasUndirected());
65+
}
3166
}

0 commit comments

Comments
 (0)