diff --git a/src/Edge/Base.php b/src/Edge/Base.php index d019c4e2..d4e94b39 100644 --- a/src/Edge/Base.php +++ b/src/Edge/Base.php @@ -2,18 +2,16 @@ namespace Fhaculty\Graph\Edge; -use Fhaculty\Graph\Vertex; -use Fhaculty\Graph\Set\Edges; -use Fhaculty\Graph\Set\Vertices; -use Fhaculty\Graph\Set\VerticesAggregate; -use Fhaculty\Graph\Graph; -use Fhaculty\Graph\Exception\LogicException; -use Fhaculty\Graph\Exception\RangeException; -use Fhaculty\Graph\Exception\UnderflowException; -use Fhaculty\Graph\Exception\InvalidArgumentException; -use Fhaculty\Graph\Exception\BadMethodCallException; use Fhaculty\Graph\Attribute\AttributeAware; use Fhaculty\Graph\Attribute\AttributeBagReference; +use Fhaculty\Graph\Exception\BadMethodCallException; +use Fhaculty\Graph\Exception\InvalidArgumentException; +use Fhaculty\Graph\Exception\LogicException; +use Fhaculty\Graph\Exception\RangeException; +use Fhaculty\Graph\Graph; +use Fhaculty\Graph\Set\Vertices; +use Fhaculty\Graph\Set\VerticesAggregate; +use Fhaculty\Graph\Vertex; abstract class Base implements VerticesAggregate, AttributeAware { @@ -21,7 +19,7 @@ abstract class Base implements VerticesAggregate, AttributeAware * weight of this edge * * @var float|int|NULL - * @see Edge::getWeight() + * @see self::getWeight() */ protected $weight = NULL; @@ -29,7 +27,7 @@ abstract class Base implements VerticesAggregate, AttributeAware * maximum capacity (maximum flow) * * @var float|int|NULL - * @see Edge::getCapacity() + * @see self::getCapacity() */ protected $capacity = NULL; @@ -37,7 +35,7 @@ abstract class Base implements VerticesAggregate, AttributeAware * flow (capacity currently in use) * * @var float|int|NULL - * @see Edge::getFlow() + * @see self::getFlow() */ protected $flow = NULL; @@ -90,17 +88,17 @@ abstract public function isLoop(); * @param Vertex $startVertex * @return Vertex * @throws InvalidArgumentException if given $startVertex is not a valid start - * @see Edge::hasEdgeFrom() to check if given start is valid + * @see self::hasEdgeFrom() to check if given start is valid */ abstract public function getVertexToFrom(Vertex $startVertex); /** * get start vertex which can reach us(the given end vertex) with this edge * - * @param Vertex $startVertex + * @param Vertex $endVertex * @return Vertex * @throws InvalidArgumentException if given $startVertex is not a valid end - * @see Edge::hasEdgeFrom() to check if given start is valid + * @see self::hasEdgeFrom() to check if given start is valid */ abstract public function getVertexFromTo(Vertex $endVertex); @@ -117,9 +115,9 @@ public function getWeight() /** * set new weight for edge * - * @param float|int|NULL $weight new numeric weight of edge or NULL=unset weight - * @return Edge $this (chainable) - * @throws DomainException if given weight is not numeric + * @param float|int|NULL $weight new numeric weight of edge or NULL=unset weight + * @return self $this (chainable) + * @throws InvalidArgumentException if given weight is not numeric */ public function setWeight($weight) { @@ -159,7 +157,7 @@ public function getCapacityRemaining() * set new total capacity of this edge * * @param float|int|NULL $capacity - * @return Edge $this (chainable) + * @return self $this (chainable) * @throws InvalidArgumentException if $capacity is invalid (not numeric or negative) * @throws RangeException if current flow exceeds new capacity */ @@ -195,7 +193,7 @@ public function getFlow() * set new total flow (capacity currently in use) * * @param float|int|NULL $flow - * @return Edge $this (chainable) + * @return self $this (chainable) * @throws InvalidArgumentException if $flow is invalid (not numeric or negative) * @throws RangeException if flow exceeds current maximum capacity */ @@ -262,7 +260,7 @@ public function destroy() /** * create new clone of this edge between adjacent vertices * - * @return Edge new edge + * @return self new edge * @uses Graph::createEdgeClone() */ public function createEdgeClone() @@ -273,7 +271,7 @@ public function createEdgeClone() /** * create new clone of this edge inverted (in opposite direction) between adjacent vertices * - * @return Edge new edge + * @return self new edge * @uses Graph::createEdgeCloneInverted() */ public function createEdgeCloneInverted() @@ -284,7 +282,7 @@ public function createEdgeCloneInverted() /** * do NOT allow cloning of objects * - * @throws Exception + * @throws BadMethodCallException */ private function __clone() { diff --git a/src/Edge/Directed.php b/src/Edge/Directed.php index 59eb3293..8b8b49f7 100644 --- a/src/Edge/Directed.php +++ b/src/Edge/Directed.php @@ -3,10 +3,8 @@ namespace Fhaculty\Graph\Edge; use Fhaculty\Graph\Exception\InvalidArgumentException; -use Fhaculty\Graph\Exception\LogicException; -use Fhaculty\Graph\Vertex; use Fhaculty\Graph\Set\Vertices; -use Fhaculty\Graph\Set\Edges; +use Fhaculty\Graph\Vertex; class Directed extends Base { diff --git a/src/Graph.php b/src/Graph.php index f5a0f98a..8ce325ea 100644 --- a/src/Graph.php +++ b/src/Graph.php @@ -2,25 +2,20 @@ namespace Fhaculty\Graph; +use Fhaculty\Graph\Attribute\AttributeAware; +use Fhaculty\Graph\Attribute\AttributeBagReference; +use Fhaculty\Graph\Edge\Base as Edge; +use Fhaculty\Graph\Edge\Directed as EdgeDirected; use Fhaculty\Graph\Exception\BadMethodCallException; -use Fhaculty\Graph\Exception\UnexpectedValueException; use Fhaculty\Graph\Exception\InvalidArgumentException; +use Fhaculty\Graph\Exception\OutOfBoundsException; use Fhaculty\Graph\Exception\OverflowException; -use Fhaculty\Graph\Exception\UnderflowException; use Fhaculty\Graph\Exception\RuntimeException; -use Fhaculty\Graph\Exception\OutOfBoundsException; -use Fhaculty\Graph\Algorithm\ConnectedComponents as AlgorithmConnectedComponents; -use Fhaculty\Graph\Algorithm\Bipartit as AlgorithmBipartit; -use Fhaculty\Graph\Algorithm\Eulerian as AlgorithmEulerian; -use Fhaculty\Graph\Algorithm\Groups as AlgorithmGroups; -use Fhaculty\Graph\Edge\Base as Edge; -use Fhaculty\Graph\Edge\Directed as EdgeDirected; +use Fhaculty\Graph\Exception\UnderflowException; +use Fhaculty\Graph\Set\DualAggregate; +use Fhaculty\Graph\Set\Edges; use Fhaculty\Graph\Set\Vertices; use Fhaculty\Graph\Set\VerticesMap; -use Fhaculty\Graph\Set\Edges; -use Fhaculty\Graph\Set\DualAggregate; -use Fhaculty\Graph\Attribute\AttributeAware; -use Fhaculty\Graph\Attribute\AttributeBagReference; class Graph implements DualAggregate, AttributeAware { diff --git a/src/Set/DualAggregate.php b/src/Set/DualAggregate.php index 6bd370c3..7cd2071e 100644 --- a/src/Set/DualAggregate.php +++ b/src/Set/DualAggregate.php @@ -2,9 +2,6 @@ namespace Fhaculty\Graph\Set; -use Fhaculty\Graph\Set\VerticesAggregate; -use Fhaculty\Graph\Set\EdgesAggregate; - /** * DualAggregate provides access to both its Vertices and its Edges * diff --git a/src/Set/Edges.php b/src/Set/Edges.php index 6b0f2ed2..f76fb852 100644 --- a/src/Set/Edges.php +++ b/src/Set/Edges.php @@ -3,15 +3,9 @@ namespace Fhaculty\Graph\Set; use Fhaculty\Graph\Edge\Base as Edge; -use Fhaculty\Graph\Exception\UnderflowException; use Fhaculty\Graph\Exception\InvalidArgumentException; use Fhaculty\Graph\Exception\OutOfBoundsException; -use Fhaculty\Graph\Exception\UnexpectedValueException; -use Countable; -use IteratorAggregate; -use IteratorIterator; -use ArrayIterator; -use Fhaculty\Graph\Set\EdgesAggregate; +use Fhaculty\Graph\Exception\UnderflowException; /** * A Set of Edges @@ -22,7 +16,7 @@ * instances or to get a new Set of Edges. This way it's safe to pass around * the original Set of Edges, because it will never be modified. */ -class Edges implements Countable, IteratorAggregate, EdgesAggregate +class Edges implements \Countable, \IteratorAggregate, EdgesAggregate { /** * order by edge weight @@ -184,7 +178,7 @@ public function getEdgeIndex($index) /** * return first Edge that matches the given callback filter function * - * @param callback $callbackCheck + * @param callable $callbackCheck * @return Edge * @throws UnderflowException if no Edge matches the given callback filter function * @uses self::getEdgeMatchOrNull() @@ -202,7 +196,7 @@ public function getEdgeMatch($callbackCheck) /** * checks whethere there's an Edge that matches the given callback filter function * - * @param callback $callbackCheck + * @param callable $callbackCheck * @return boolean * @see self::getEdgeMatch() to return the Edge instance that matches the given callback filter function * @uses self::getEdgeMatchOrNull() @@ -413,11 +407,11 @@ public function isEmpty() * This method implements the IteratorAggregate interface and allows this * Set of Edges to be used in foreach loops. * - * @return IteratorIterator + * @return \IteratorIterator */ public function getIterator() { - return new IteratorIterator(new ArrayIterator($this->edges)); + return new \IteratorIterator(new \ArrayIterator($this->edges)); } /** @@ -458,7 +452,7 @@ private function getEdgeMatchOrNull($callbackCheck) * * @param callable|int $callback * @throws InvalidArgumentException - * @return Closure + * @return callable */ private function getCallback($callback) { diff --git a/src/Set/EdgesAggregate.php b/src/Set/EdgesAggregate.php index ab73c420..9ede4983 100644 --- a/src/Set/EdgesAggregate.php +++ b/src/Set/EdgesAggregate.php @@ -2,8 +2,6 @@ namespace Fhaculty\Graph\Set; -use Fhaculty\Graph\Set\Edges; - /** * Basic interface for every class that provides access to its Set of Edges */ diff --git a/src/Set/Vertices.php b/src/Set/Vertices.php index e20af5f0..e11a1f06 100644 --- a/src/Set/Vertices.php +++ b/src/Set/Vertices.php @@ -3,16 +3,9 @@ namespace Fhaculty\Graph\Set; use Fhaculty\Graph\Vertex; -use Fhaculty\Graph\Exception\UnderflowException; use Fhaculty\Graph\Exception\InvalidArgumentException; use Fhaculty\Graph\Exception\OutOfBoundsException; -use Fhaculty\Graph\Exception\UnexpectedValueException; -use Countable; -use IteratorAggregate; -use IteratorIterator; -use ArrayIterator; -use Fhaculty\Graph\Set\VerticesAggregate; -use Fhaculty\Graph\Set\VerticesMap; +use Fhaculty\Graph\Exception\UnderflowException; /** * A Set of Vertices @@ -23,7 +16,7 @@ * instances or to get a new Set of Vertices. This way it's safe to pass around * the original Set of Vertices, because it will never be modified. */ -class Vertices implements Countable, IteratorAggregate, VerticesAggregate +class Vertices implements \Countable, \IteratorAggregate, VerticesAggregate { /** * order by vertex ID @@ -187,7 +180,7 @@ public function getVertexLast() /** * return first Vertex that matches the given callback filter function * - * @param callback $callbackCheck + * @param callable $callbackCheck * @return Vertex * @throws UnderflowException if no Vertex matches the given callback filter function * @uses self::getVertexMatchOrNull() @@ -205,7 +198,7 @@ public function getVertexMatch($callbackCheck) /** * checks whether there's a Vertex that matches the given callback filter function * - * @param callback $callbackCheck + * @param callable $callbackCheck * @return boolean * @see self::getVertexMatch() to return the Vertex instance that matches the given callback filter function * @uses self::getVertexMatchOrNull() @@ -453,11 +446,11 @@ public function hasDuplicates() * This method implements the IteratorAggregate interface and allows this * Set of Vertices to be used in foreach loops. * - * @return IteratorIterator + * @return \IteratorIterator */ public function getIterator() { - return new IteratorIterator(new ArrayIterator($this->vertices)); + return new \IteratorIterator(new \ArrayIterator($this->vertices)); } /** @@ -505,7 +498,7 @@ private function getVertexMatchOrNull($callbackCheck) * * @param callable|int $callback * @throws InvalidArgumentException - * @return Closure + * @return callable */ private function getCallback($callback) { diff --git a/src/Set/VerticesAggregate.php b/src/Set/VerticesAggregate.php index b67afd87..47a44283 100644 --- a/src/Set/VerticesAggregate.php +++ b/src/Set/VerticesAggregate.php @@ -2,8 +2,6 @@ namespace Fhaculty\Graph\Set; -use Fhaculty\Graph\Set\Vertices; - /** * Basic interface for every class that provides access to its Set of Vertices */ diff --git a/src/Set/VerticesMap.php b/src/Set/VerticesMap.php index 660e724f..315d2f41 100644 --- a/src/Set/VerticesMap.php +++ b/src/Set/VerticesMap.php @@ -2,10 +2,8 @@ namespace Fhaculty\Graph\Set; -use Fhaculty\Graph\Vertex; use Fhaculty\Graph\Exception\OutOfBoundsException; -use Fhaculty\Graph\Exception\InvalidArgumentException; -use Fhaculty\Graph\Set\Vertices; +use Fhaculty\Graph\Vertex; /** * A set of Vertices that are already stored in a vertex ID => Vertex instance mapping array diff --git a/src/Vertex.php b/src/Vertex.php index 5dfa83a1..13e5b9cf 100644 --- a/src/Vertex.php +++ b/src/Vertex.php @@ -2,17 +2,16 @@ namespace Fhaculty\Graph; +use Fhaculty\Graph\Attribute\AttributeAware; +use Fhaculty\Graph\Attribute\AttributeBagReference; use Fhaculty\Graph\Edge\Base as Edge; use Fhaculty\Graph\Edge\Directed as EdgeDirected; use Fhaculty\Graph\Edge\Undirected as EdgeUndirected; +use Fhaculty\Graph\Exception\BadMethodCallException; +use Fhaculty\Graph\Exception\InvalidArgumentException; use Fhaculty\Graph\Set\Edges; use Fhaculty\Graph\Set\EdgesAggregate; use Fhaculty\Graph\Set\Vertices; -use Fhaculty\Graph\Exception\BadMethodCallException; -use Fhaculty\Graph\Exception\UnexpectedValueException; -use Fhaculty\Graph\Exception\InvalidArgumentException; -use Fhaculty\Graph\Attribute\AttributeAware; -use Fhaculty\Graph\Attribute\AttributeBagReference; class Vertex implements EdgesAggregate, AttributeAware { @@ -31,7 +30,7 @@ class Vertex implements EdgesAggregate, AttributeAware /** * vertex balance * - * @var float|NULL + * @var int|float|NULL * @see Vertex::setBalance() */ private $balance; diff --git a/src/Walk.php b/src/Walk.php index c825e5f9..e86960db 100644 --- a/src/Walk.php +++ b/src/Walk.php @@ -53,14 +53,12 @@ public static function factoryFromEdges($edges, Vertex $startVertex) public static function factoryFromVertices($vertices, $by = null, $desc = false) { $edges = array(); - $first = NULL; $last = NULL; foreach ($vertices as $vertex) { // skip first vertex as last is unknown - if ($first === NULL) { - $first = $vertex; - } else { + if ($last !== NULL) { // pick edge between last vertex and this vertex + /* @var $last Vertex */ if ($by === null) { $edges []= $last->getEdgesTo($vertex)->getEdgeFirst(); } else { diff --git a/tests/Exception/NegativeCycleExceptionTest.php b/tests/Exception/NegativeCycleExceptionTest.php index 34118af7..364bfb10 100644 --- a/tests/Exception/NegativeCycleExceptionTest.php +++ b/tests/Exception/NegativeCycleExceptionTest.php @@ -2,9 +2,8 @@ namespace Fhaculty\Graph\Tests\Exception; -use Fhaculty\Graph\Tests\TestCase; -use Fhaculty\Graph\Walk; use Fhaculty\Graph\Exception\NegativeCycleException; +use Fhaculty\Graph\Tests\TestCase; class NegativeCycleExceptionTest extends TestCase { diff --git a/tests/GraphTest.php b/tests/GraphTest.php index e72239c8..a8bea3bb 100644 --- a/tests/GraphTest.php +++ b/tests/GraphTest.php @@ -2,12 +2,10 @@ namespace Fhaculty\Graph\Tests; -use Fhaculty\Graph\Exception\RuntimeException; -use Fhaculty\Graph\Tests\Attribute\AbstractAttributeAwareTest; -use Fhaculty\Graph\Vertex; use Fhaculty\Graph\Exception\OverflowException; use Fhaculty\Graph\Exception\InvalidArgumentException; use Fhaculty\Graph\Graph; +use Fhaculty\Graph\Tests\Attribute\AbstractAttributeAwareTest; class GraphTest extends AbstractAttributeAwareTest { diff --git a/tests/Set/BaseVerticesTest.php b/tests/Set/BaseVerticesTest.php index 6e8d6eec..06b0a3ac 100644 --- a/tests/Set/BaseVerticesTest.php +++ b/tests/Set/BaseVerticesTest.php @@ -2,11 +2,10 @@ namespace Fhaculty\Graph\Tests\Set; -use Fhaculty\Graph\Exception\OutOfBoundsException; use Fhaculty\Graph\Graph; +use Fhaculty\Graph\Set\Vertices; use Fhaculty\Graph\Tests\TestCase; use Fhaculty\Graph\Vertex; -use Fhaculty\Graph\Set\Vertices; abstract class BaseVerticesTest extends TestCase { diff --git a/tests/Set/EdgesTest.php b/tests/Set/EdgesTest.php index 11cedc9d..df0b0902 100644 --- a/tests/Set/EdgesTest.php +++ b/tests/Set/EdgesTest.php @@ -2,12 +2,10 @@ namespace Fhaculty\Graph\Tests\Set; -use Fhaculty\Graph\Exception\OutOfBoundsException; -use Fhaculty\Graph\Graph; -use Fhaculty\Graph\Tests\TestCase; -use Fhaculty\Graph\Vertex; use Fhaculty\Graph\Edge\Base as Edge; +use Fhaculty\Graph\Graph; use Fhaculty\Graph\Set\Edges; +use Fhaculty\Graph\Tests\TestCase; class EdgesTest extends TestCase { diff --git a/tests/Set/VerticesTest.php b/tests/Set/VerticesTest.php index a6288abf..00c89b8d 100644 --- a/tests/Set/VerticesTest.php +++ b/tests/Set/VerticesTest.php @@ -2,9 +2,8 @@ namespace Fhaculty\Graph\Tests\Set; -use Fhaculty\Graph\Set\Vertices; use Fhaculty\Graph\Graph; -use Fhaculty\Graph\Exception\InvalidArgumentException; +use Fhaculty\Graph\Set\Vertices; class VerticesTest extends BaseVerticesTest { diff --git a/tests/WalkTest.php b/tests/WalkTest.php index 775f0340..41fade59 100644 --- a/tests/WalkTest.php +++ b/tests/WalkTest.php @@ -3,10 +3,9 @@ namespace Fhaculty\Graph\Tests; use Fhaculty\Graph\Graph; -use Fhaculty\Graph\Walk; -use Fhaculty\Graph\Algorithm\Property\WalkProperty; -use Fhaculty\Graph\Vertex; use Fhaculty\Graph\Set\Edges; +use Fhaculty\Graph\Vertex; +use Fhaculty\Graph\Walk; class WalkTest extends TestCase {