Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Attribute/AttributeBagNamespaced.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ public function removeAttribute($name)
public function getAttributes()
{
$attributes = array();
$len = strlen($this->prefix);
$len = \strlen($this->prefix);

foreach ($this->bag->getAttributes() as $name => $value) {
if (strpos($name, $this->prefix) === 0) {
$attributes[substr($name, $len)] = $value;
if (\strpos($name, $this->prefix) === 0) {
$attributes[\substr($name, $len)] = $value;
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,14 @@ public function createEdgeDirected(Vertex $source, Vertex $target)
public function createVertices($n)
{
$vertices = array();
if (is_int($n) && $n >= 0) {
if (\is_int($n) && $n >= 0) {
for ($id = $this->getNextId(), $n += $id; $id < $n; ++$id) {
$vertices[$id] = new Vertex($this, $id);
}
} elseif (is_array($n)) {
} elseif (\is_array($n)) {
// array given => check to make sure all given IDs are available (atomic operation)
foreach ($n as $id) {
if (!is_int($id) && !is_string($id)) {
if (!\is_int($id) && !\is_string($id)) {
throw new InvalidArgumentException('All Vertex IDs have to be of type integer or string');
} elseif ($this->vertices->hasVertexId($id)) {
throw new OverflowException('Given array of Vertex IDs contains an ID that already exists. Given IDs must be unique');
Expand Down Expand Up @@ -159,7 +159,7 @@ private function getNextId()
}

// auto ID
return max(array_keys($this->verticesStorage))+1;
return \max(\array_keys($this->verticesStorage))+1;
}

/**
Expand Down Expand Up @@ -267,22 +267,22 @@ public function __clone()

$map = array();
foreach ($vertices as $originalVertex) {
assert($originalVertex instanceof Vertex);
\assert($originalVertex instanceof Vertex);

$vertex = new Vertex($this, $originalVertex->getId());
$vertex->getAttributeBag()->setAttributes($originalVertex->getAttributeBag()->getAttributes());

// create map with old vertex hash to new vertex object
$map[spl_object_hash($originalVertex)] = $vertex;
$map[\spl_object_hash($originalVertex)] = $vertex;
}

foreach ($edges as $originalEdge) {
assert($originalEdge instanceof Edge);
\assert($originalEdge instanceof Edge);

// use map to match old vertex hashes to new vertex objects
$vertices = $originalEdge->getVertices()->getVector();
$v1 = $map[spl_object_hash($vertices[0])];
$v2 = $map[spl_object_hash($vertices[1])];
$v1 = $map[\spl_object_hash($vertices[0])];
$v2 = $map[\spl_object_hash($vertices[1])];

// recreate edge and assign attributes
if ($originalEdge instanceof EdgeUndirected) {
Expand Down
34 changes: 17 additions & 17 deletions src/Set/Edges.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function __construct(array $edges = array())
*/
public function getIndexEdge(Edge $edge)
{
$id = array_search($edge, $this->edges, true);
$id = \array_search($edge, $this->edges, true);
if ($id === false) {
throw new OutOfBoundsException('Given edge does NOT exist');
}
Expand All @@ -99,9 +99,9 @@ public function getEdgeFirst()
if (!$this->edges) {
throw new UnderflowException('Does not contain any edges');
}
reset($this->edges);
\reset($this->edges);

return current($this->edges);
return \current($this->edges);
}

/**
Expand All @@ -115,9 +115,9 @@ public function getEdgeLast()
if (!$this->edges) {
throw new UnderflowException('Does not contain any edges');
}
end($this->edges);
\end($this->edges);

return current($this->edges);
return \current($this->edges);
}

/**
Expand All @@ -133,7 +133,7 @@ public function getEdgeRandom()
throw new UnderflowException('Does not contain any edges');
}

return $this->edges[array_rand($this->edges)];
return $this->edges[\array_rand($this->edges)];
}

/**
Expand Down Expand Up @@ -196,7 +196,7 @@ public function hasEdgeMatch($callbackCheck)
*/
public function getEdgesMatch($callbackCheck)
{
return new static(array_filter($this->edges, $callbackCheck));
return new static(\array_filter($this->edges, $callbackCheck));
}

/**
Expand All @@ -213,7 +213,7 @@ public function getEdgesOrder($orderBy, $desc = false)
$callback = $this->getCallback($orderBy);
$array = $this->edges;

uasort($array, function (Edge $va, Edge $vb) use ($callback, $desc) {
\uasort($array, function (Edge $va, Edge $vb) use ($callback, $desc) {
$ra = $callback($desc ? $vb : $va);
$rb = $callback($desc ? $va : $vb);

Expand Down Expand Up @@ -242,8 +242,8 @@ public function getEdgesOrder($orderBy, $desc = false)
public function getEdgesShuffled()
{
// shuffle the edge positions
$keys = array_keys($this->edges);
shuffle($keys);
$keys = \array_keys($this->edges);
\shuffle($keys);

// re-order according to shuffled edge positions
$edges = array();
Expand Down Expand Up @@ -305,7 +305,7 @@ public function getEdgesDistinct()
$edges = array();
foreach ($this->edges as $edge) {
// filter duplicate edges
if (!in_array($edge, $edges, true)) {
if (!\in_array($edge, $edges, true)) {
$edges []= $edge;
}
}
Expand Down Expand Up @@ -333,7 +333,7 @@ public function getEdgesIntersection($otherEdges)

$edges = array();
foreach ($this->edges as $eid => $edge) {
$i = array_search($edge, $otherArray, true);
$i = \array_search($edge, $otherArray, true);

if ($i !== false) {
// remove from other array in order to check for duplicate matches
Expand All @@ -353,7 +353,7 @@ public function getEdgesIntersection($otherEdges)
*/
public function getVector()
{
return array_values($this->edges);
return \array_values($this->edges);
}

/**
Expand All @@ -364,7 +364,7 @@ public function getVector()
*/
public function count()
{
return count($this->edges);
return \count($this->edges);
}

/**
Expand Down Expand Up @@ -431,10 +431,10 @@ private function getEdgeMatchOrNull($callbackCheck)
*/
private function getCallback($callback)
{
if (is_callable($callback)) {
if (is_array($callback)) {
if (\is_callable($callback)) {
if (\is_array($callback)) {
$callback = function (Edge $edge) use ($callback) {
return call_user_func($callback, $edge);
return \call_user_func($callback, $edge);
};
}
return $callback;
Expand Down
34 changes: 17 additions & 17 deletions src/Set/Vertices.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function hasVertexId($id)
*/
public function getIndexVertex(Vertex $vertex)
{
$id = array_search($vertex, $this->vertices, true);
$id = \array_search($vertex, $this->vertices, true);
if ($id === false) {
throw new OutOfBoundsException('Given vertex does NOT exist');
}
Expand All @@ -132,9 +132,9 @@ public function getVertexFirst()
if (!$this->vertices) {
throw new UnderflowException('Does not contain any vertices');
}
reset($this->vertices);
\reset($this->vertices);

return current($this->vertices);
return \current($this->vertices);
}

/**
Expand All @@ -148,9 +148,9 @@ public function getVertexLast()
if (!$this->vertices) {
throw new UnderflowException('Does not contain any vertices');
}
end($this->vertices);
\end($this->vertices);

return current($this->vertices);
return \current($this->vertices);
}

/**
Expand All @@ -166,7 +166,7 @@ public function getVertexRandom()
throw new UnderflowException('Does not contain any vertices');
}

return $this->vertices[array_rand($this->vertices)];
return $this->vertices[\array_rand($this->vertices)];
}

/**
Expand Down Expand Up @@ -215,7 +215,7 @@ public function hasVertexMatch($callbackCheck)
*/
public function getVerticesMatch($callbackCheck)
{
return new static(array_filter($this->vertices, $callbackCheck));
return new static(\array_filter($this->vertices, $callbackCheck));
}

/**
Expand All @@ -234,7 +234,7 @@ public function getVerticesOrder($orderBy, $desc = false)
$callback = $this->getCallback($orderBy);
$array = $this->vertices;

uasort($array, function (Vertex $va, Vertex $vb) use ($callback, $desc) {
\uasort($array, function (Vertex $va, Vertex $vb) use ($callback, $desc) {
$ra = $callback($desc ? $vb : $va);
$rb = $callback($desc ? $va : $vb);

Expand Down Expand Up @@ -263,8 +263,8 @@ public function getVerticesOrder($orderBy, $desc = false)
public function getVerticesShuffled()
{
// shuffle the vertex positions
$keys = array_keys($this->vertices);
shuffle($keys);
$keys = \array_keys($this->vertices);
\shuffle($keys);

// re-order according to shuffled vertex positions
$vertices = array();
Expand Down Expand Up @@ -295,7 +295,7 @@ public function getVerticesIntersection($otherVertices)

$vertices = array();
foreach ($this->vertices as $vid => $vertex) {
$i = array_search($vertex, $otherArray, true);
$i = \array_search($vertex, $otherArray, true);

if ($i !== false) {
// remove from other array in order to check for duplicate matches
Expand Down Expand Up @@ -397,7 +397,7 @@ public function getIds()
*/
public function getVector()
{
return array_values($this->vertices);
return \array_values($this->vertices);
}

/**
Expand All @@ -408,7 +408,7 @@ public function getVector()
*/
public function count()
{
return count($this->vertices);
return \count($this->vertices);
}

/**
Expand All @@ -432,7 +432,7 @@ public function isEmpty()
*/
public function hasDuplicates()
{
return (count($this->vertices) !== count($this->getMap()));
return (\count($this->vertices) !== \count($this->getMap()));
}

/**
Expand Down Expand Up @@ -493,10 +493,10 @@ private function getVertexMatchOrNull($callbackCheck)
*/
private function getCallback($callback)
{
if (is_callable($callback)) {
if (is_array($callback)) {
if (\is_callable($callback)) {
if (\is_array($callback)) {
$callback = function (Vertex $vertex) use ($callback) {
return call_user_func($callback, $vertex);
return \call_user_func($callback, $vertex);
};
}
return $callback;
Expand Down
2 changes: 1 addition & 1 deletion src/Set/VerticesMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getVerticesDistinct()

public function getIds()
{
return array_keys($this->vertices);
return \array_keys($this->vertices);
}

public function getIndexVertex(Vertex $vertex)
Expand Down
4 changes: 2 additions & 2 deletions src/Vertex.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Vertex implements EdgesAggregate, AttributeAware
*/
public function __construct(Graph $graph, $id)
{
if (!is_int($id) && !is_string($id)) {
if (!\is_int($id) && !\is_string($id)) {
throw new InvalidArgumentException('Vertex ID has to be of type integer or string');
}

Expand Down Expand Up @@ -89,7 +89,7 @@ public function addEdge(Edge $edge)
*/
public function removeEdge(Edge $edge)
{
$id = array_search($edge, $this->edges, true);
$id = \array_search($edge, $this->edges, true);
if ($id === false) {
throw new InvalidArgumentException('Given edge does NOT exist');
}
Expand Down
8 changes: 4 additions & 4 deletions src/Walk.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ public static function factoryCycleFromPredecessorMap(array $predecessors, Verte
} while (!isset($vertices[$vid]));

// reverse cycle, because cycle is actually built in opposite direction due to checking predecessors
$vertices = array_reverse($vertices, true);
$vertices = \array_reverse($vertices, true);

// additional edge from last vertex to first vertex
$vertices[] = reset($vertices);
$vertices[] = \reset($vertices);

return self::factoryCycleFromVertices($vertices, $orderBy, $desc);
}
Expand Down Expand Up @@ -245,7 +245,7 @@ public function getAlternatingSequence()
$vertices = $this->vertices->getVector();

$ret = array();
for ($i = 0, $l = count($this->edges); $i < $l; ++$i) {
for ($i = 0, $l = \count($this->edges); $i < $l; ++$i) {
$ret []= $vertices[$i];
$ret []= $edges[$i];
}
Expand Down Expand Up @@ -275,7 +275,7 @@ public function isValid()
$edges = $this->getGraph()->getEdges()->getVector();
// check source graph contains all edges
foreach ($this->edges as $edge) {
if (!in_array($edge, $edges, true)) {
if (!\in_array($edge, $edges, true)) {
return false;
}
}
Expand Down