Skip to content

Commit 731a768

Browse files
committed
Minor code style improvements to make PHPStan happy
1 parent d797842 commit 731a768

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+262
-380
lines changed

src/BaseDual.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
namespace Graphp\Algorithms;
44

5-
use Graphp\Algorithms\Base;
6-
use Fhaculty\Graph\Set\DualAggregate;
75
use Fhaculty\Graph\Graph;
6+
use Fhaculty\Graph\Set\DualAggregate;
87
use Fhaculty\Graph\Walk;
98

109
/**
@@ -25,7 +24,7 @@ abstract class BaseDual extends Base
2524
/**
2625
* instantiate new algorithm
2726
*
28-
* @param Graph|Walk|Set $graphOrWalk either the Graph or Walk to operate on (or the common base class Set)
27+
* @param Graph|Walk|DualAggregate $graphOrWalk either the Graph or Walk to operate on (or the common base class Set)
2928
*/
3029
public function __construct(DualAggregate $graphOrWalk)
3130
{

src/BaseGraph.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Graphp\Algorithms;
44

5-
use Graphp\Algorithms\Base;
65
use Fhaculty\Graph\Graph;
76

87
/**

src/BaseVertex.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Graphp\Algorithms;
44

5-
use Graphp\Algorithms\Base;
65
use Fhaculty\Graph\Vertex;
76

87
/**

src/Bipartit.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22

33
namespace Graphp\Algorithms;
44

5-
use Graphp\Algorithms\BaseGraph;
65
use Fhaculty\Graph\Exception\UnexpectedValueException;
76
use Fhaculty\Graph\Graph;
8-
use Fhaculty\Graph\Vertex;
97

108
class Bipartit extends BaseGraph
119
{
1210
/**
1311
* check whether this graph is bipartit
1412
*
15-
* @return boolean
13+
* @return bool
1614
* @uses AlgorithmBipartit::getColors()
1715
*/
1816
public function isBipartit()
@@ -29,7 +27,7 @@ public function isBipartit()
2927
/**
3028
* checks whether the input graph's vertex groups are a valid bipartition
3129
*
32-
* @return boolean
30+
* @return bool
3331
* @uses AlgorithmGroups::isBipartit()
3432
*/
3533
public function isBipartitGroups()
@@ -69,7 +67,7 @@ public function getColors()
6967
// color unknown, so expect next color for this vertex
7068
if (!isset($colors[$vid])) {
7169
$colors[$vid] = $nextColor;
72-
$queue []= $nextVertex;
70+
$queue[] = $nextVertex;
7371
// color is known but differs => can not be bipartit
7472
} elseif ($colors[$vid] !== $nextColor) {
7573
throw new UnexpectedValueException('Graph is not bipartit');

src/Complete.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
namespace Graphp\Algorithms;
44

5-
use Graphp\Algorithms\BaseGraph;
6-
use Fhaculty\Graph\Graph;
7-
85
/**
96
* Basic algorithms for working with complete graphs
107
*
@@ -19,7 +16,7 @@ class Complete extends BaseGraph
1916
/**
2017
* checks whether this graph is complete (every vertex has an edge to any other vertex)
2118
*
22-
* @return boolean
19+
* @return bool
2320
* @uses Graph::getVertices()
2421
* @uses Vertex::hasEdgeTo()
2522
*/

src/ConnectedComponents.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22

33
namespace Graphp\Algorithms;
44

5-
use Graphp\Algorithms\BaseGraph;
6-
use Graphp\Algorithms\Search\BreadthFirst as SearchBreadthFirst;
7-
use Fhaculty\Graph\Graph;
8-
use Fhaculty\Graph\Vertex;
95
use Fhaculty\Graph\Exception\InvalidArgumentException;
106
use Fhaculty\Graph\Exception\UnderflowException;
7+
use Fhaculty\Graph\Graph;
8+
use Fhaculty\Graph\Vertex;
9+
use Graphp\Algorithms\Search\BreadthFirst as SearchBreadthFirst;
1110

1211
/**
1312
* Algorithm for working with connected components
@@ -64,15 +63,14 @@ private function createSearch(Vertex $vertex)
6463
* As such, a null Graph (a Graph with no vertices) is not considered
6564
* connected here.
6665
*
67-
* @return boolean
66+
* @return bool
6867
* @see self::getNumberOfComponents()
6968
*/
7069
public function isSingle()
7170
{
7271
try {
7372
$vertex = $this->graph->getVertices()->getVertexFirst();
74-
}
75-
catch (UnderflowException $e) {
73+
} catch (UnderflowException $e) {
7674
// no first vertex => empty graph => has zero components
7775
return false;
7876
}
@@ -142,7 +140,7 @@ public function createGraphsComponents()
142140
$visitedVertices[$vid] = true;
143141
}
144142

145-
$graphs []= $this->graph->createGraphCloneVertices($newVertices);
143+
$graphs[] = $this->graph->createGraphCloneVertices($newVertices);
146144
}
147145
}
148146

src/Degree.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@
22

33
namespace Graphp\Algorithms;
44

5-
use Graphp\Algorithms\BaseGraph;
6-
use Fhaculty\Graph\Graph;
7-
use Fhaculty\Graph\Vertex;
5+
use Fhaculty\Graph\Exception\UnderflowException;
86
use Fhaculty\Graph\Exception\UnexpectedValueException;
9-
use Fhaculty\Graph\Set\Vertices;
7+
use Fhaculty\Graph\Vertex;
108

119
/**
1210
* Basic algorithms for working with the degrees of Graphs.
@@ -34,7 +32,7 @@ public function getDegree()
3432
$degree = $this->getDegreeVertex($this->graph->getVertices()->getVertexFirst());
3533

3634
foreach ($this->graph->getVertices() as $vertex) {
37-
/** @var $vertex Vertex */
35+
assert($vertex instanceof Vertex);
3836
$i = $this->getDegreeVertex($vertex);
3937

4038
if ($i !== $degree) {
@@ -49,7 +47,7 @@ public function getDegree()
4947
* get minimum degree of vertices
5048
*
5149
* @return int
52-
* @throws Exception if graph is empty or directed
50+
* @throws UnderflowException if graph is empty
5351
* @uses Vertices::getVertexOrder()
5452
* @uses self::getDegreeVertex()
5553
*/
@@ -62,7 +60,7 @@ public function getDegreeMin()
6260
* get maximum degree of vertices
6361
*
6462
* @return int
65-
* @throws Exception if graph is empty or directed
63+
* @throws UnderflowException if graph is empty
6664
* @uses Vertices::getVertexOrder()
6765
* @uses self::getDegreeVertex()
6866
*/
@@ -74,7 +72,7 @@ public function getDegreeMax()
7472
/**
7573
* checks whether this graph is regular, i.e. each vertex has the same indegree/outdegree
7674
*
77-
* @return boolean
75+
* @return bool
7876
* @uses self::getDegree()
7977
*/
8078
public function isRegular()
@@ -95,7 +93,7 @@ public function isRegular()
9593
/**
9694
* checks whether the indegree of every vertex equals its outdegree
9795
*
98-
* @return boolean
96+
* @return bool
9997
* @uses self::getDegreeInVertex()
10098
* @uses self::getDegreeOutVertex()
10199
*/
@@ -114,7 +112,7 @@ public function isBalanced()
114112
* checks whether this vertex is a source, i.e. its indegree is zero
115113
*
116114
* @param Vertex $vertex
117-
* @return boolean
115+
* @return bool
118116
* @uses Edge::hasVertexTarget()
119117
* @see self::getDegreeInVertex()
120118
*/
@@ -134,7 +132,7 @@ public function isVertexSource(Vertex $vertex)
134132
* checks whether this vertex is a sink, i.e. its outdegree is zero
135133
*
136134
* @param Vertex $vertex
137-
* @return boolean
135+
* @return bool
138136
* @uses Edge::hasVertexStart()
139137
* @see self::getDegreeOutVertex()
140138
*/
@@ -171,7 +169,7 @@ public function getDegreeVertex(Vertex $vertex)
171169
* check whether this vertex is isolated (i.e. has no edges attached)
172170
*
173171
* @param Vertex $vertex
174-
* @return boolean
172+
* @return bool
175173
*/
176174
public function isVertexIsolated(Vertex $vertex)
177175
{

src/DetectNegativeCycle.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,18 @@
22

33
namespace Graphp\Algorithms;
44

5-
use Graphp\Algorithms\BaseGraph;
5+
use Fhaculty\Graph\Exception\NegativeCycleException;
66
use Fhaculty\Graph\Exception\UnderflowException;
7-
87
use Fhaculty\Graph\Graph;
9-
use Fhaculty\Graph\Vertex;
108
use Fhaculty\Graph\Walk;
11-
use Fhaculty\Graph\Exception\NegativeCycleException;
129
use Graphp\Algorithms\ShortestPath\MooreBellmanFord as SpMooreBellmanFord;
1310

1411
class DetectNegativeCycle extends BaseGraph
1512
{
1613
/**
1714
* check if the input graph has any negative cycles
1815
*
19-
* @return boolean
16+
* @return bool
2017
* @uses AlgorithmDetectNegativeCycle::getCycleNegative()
2118
*/
2219
public function hasCycleNegative()
@@ -71,7 +68,7 @@ public function getCycleNegative()
7168
* create new graph clone with only vertices and edges in negative cycle
7269
*
7370
* @return Graph
74-
* @throws Exception if there's no negative cycle
71+
* @throws UnderflowException if there's no negative cycle
7572
* @uses AlgorithmDetectNegativeCycle::getCycleNegative()
7673
* @uses Walk::createGraph()
7774
*/

src/Directed.php

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

33
namespace Graphp\Algorithms;
44

5-
use Graphp\Algorithms\BaseGraph;
65
use Fhaculty\Graph\Edge\Directed as EdgeDirected;
76
use Fhaculty\Graph\Edge\Undirected as EdgeUndirected;
87

@@ -20,7 +19,7 @@ class Directed extends BaseDual
2019
* This method is intentionally not named "isDirected()" (aka digraph),
2120
* because that might be misleading in regards to empty and/or mixed graphs.
2221
*
23-
* @return boolean
22+
* @return bool
2423
*/
2524
public function hasDirected()
2625
{
@@ -39,7 +38,7 @@ public function hasDirected()
3938
* This method is intentionally not named "isUndirected()",
4039
* because that might be misleading in regards to empty and/or mixed graphs.
4140
*
42-
* @return boolean
41+
* @return bool
4342
*/
4443
public function hasUndirected()
4544
{
@@ -55,7 +54,7 @@ public function hasUndirected()
5554
/**
5655
* checks whether this is a mixed graph (contains both directed and undirected edges)
5756
*
58-
* @return boolean
57+
* @return bool
5958
* @uses self::hasDirected()
6059
* @uses self::hasUndirected()
6160
*/

src/Eulerian.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22

33
namespace Graphp\Algorithms;
44

5-
use Graphp\Algorithms\BaseGraph;
6-
use Fhaculty\Graph\Graph;
7-
use Graphp\Algorithms\Degree;
8-
95
class Eulerian extends BaseGraph
106
{
117
/**
128
* check whether this graph has an eulerian cycle
139
*
14-
* @return boolean
10+
* @return bool
1511
* @uses ConnectedComponents::isSingle()
1612
* @uses Degree::getDegreeVertex()
1713
* @todo isolated vertices should be ignored

0 commit comments

Comments
 (0)