Skip to content

Commit

Permalink
Updated: Code to work with older PHP version
Browse files Browse the repository at this point in the history
  • Loading branch information
ikwilkoffie committed Aug 21, 2018
1 parent 9e220a2 commit 9e0397e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
14 changes: 7 additions & 7 deletions src/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function setOptions($options)
* @throws \Ikwilkoffie\Tree\Exception\InvalidParentException
* @throws \Ikwilkoffie\Tree\Exception\InvalidDatatypeException
*/
public function rebuildWithData(array $data)
public function rebuildWithData($data)
{
$this->build($data);
}
Expand All @@ -109,7 +109,7 @@ public function rebuildWithData(array $data)
* the first level 1 item (and their children), then
* the second level 1 item and so on.
*/
public function getNodes(): array
public function getNodes()
{
$nodes = [];
foreach ($this->nodes[$this->rootId]->getDescendants() as $subnode) {
Expand All @@ -128,7 +128,7 @@ public function getNodes(): array
*
* @return Node
*/
public function getNodeById($id): Node
public function getNodeById($id)
{
if (empty($this->nodes[$id])) {
throw new \InvalidArgumentException("Invalid node primary key $id");
Expand All @@ -142,7 +142,7 @@ public function getNodeById($id): Node
*
* @return Node[] Nodes in the correct order
*/
public function getRootNodes(): array
public function getRootNodes()
{
return $this->nodes[$this->rootId]->getChildren();
}
Expand All @@ -161,9 +161,9 @@ public function getRootNodes(): array
*
* @return Node|null
*/
public function getNodeByValuePath($name, array $search)
public function getNodeByValuePath($name, $search)
{
$findNested = function (array $nodes, array $tokens) use ($name, &$findNested) {
$findNested = function ($nodes, $tokens) use ($name, &$findNested) {
$token = array_shift($tokens);
foreach ($nodes as $node) {
$nodeName = $node->get($name);
Expand Down Expand Up @@ -278,7 +278,7 @@ public function jsonSerialize()
*
* @return Node
*/
protected function createNode($id, $parent, array $properties): Node
protected function createNode($id, $parent, $properties)
{
return new Node($id, $parent, $properties);
}
Expand Down
36 changes: 18 additions & 18 deletions src/Tree/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class Node implements \JsonSerializable
* @param string|int $parent
* @param array $properties Associative array of node properties
*/
public function __construct($id, $parent, array $properties = [])
public function __construct($id, $parent, $properties = [])
{
$this->properties = array_change_key_case($properties, CASE_LOWER);
unset($this->properties['id'], $this->properties['parent']);
Expand All @@ -50,7 +50,7 @@ public function __construct($id, $parent, array $properties = [])
*
* @param Node $child
*/
public function addChild(Node $child)
public function addChild($child)
{
$this->children[] = $child;
$child->parent = $this;
Expand Down Expand Up @@ -84,7 +84,7 @@ public function getFollowingSibling()
*
* @return Node|null
*/
private function getSibling(int $offset)
private function getSibling($offset)
{
$siblingsAndSelf = $this->parent->getChildren();
$pos = array_search($this, $siblingsAndSelf, true);
Expand All @@ -100,7 +100,7 @@ private function getSibling(int $offset)
*
* @return Node[]
*/
public function getSiblings(): array
public function getSiblings()
{
return $this->getSiblingsGeneric(false);
}
Expand All @@ -110,7 +110,7 @@ public function getSiblings(): array
*
* @return Node[]
*/
public function getSiblingsAndSelf(): array
public function getSiblingsAndSelf()
{
return $this->getSiblingsGeneric(true);
}
Expand All @@ -120,7 +120,7 @@ public function getSiblingsAndSelf(): array
*
* @return array
*/
protected function getSiblingsGeneric(bool $includeSelf): array
protected function getSiblingsGeneric(bool $includeSelf)
{
$siblings = [];
foreach ($this->parent->getChildren() as $child) {
Expand All @@ -137,7 +137,7 @@ protected function getSiblingsGeneric(bool $includeSelf): array
*
* @return Node[]
*/
public function getChildren(): array
public function getChildren()
{
return $this->children;
}
Expand All @@ -149,7 +149,7 @@ public function getChildren(): array
*/
public function getParent()
{
return $this->parent ?? null;
return $this->parent ? $this->parent : null;
}

/**
Expand Down Expand Up @@ -240,7 +240,7 @@ public function __isset($name)
*
* @return int Tree level (1 = top level)
*/
public function getLevel(): int
public function getLevel()
{
if (null === $this->parent) {
return 0;
Expand All @@ -254,7 +254,7 @@ public function getLevel(): int
*
* @return bool
*/
public function hasChildren(): bool
public function hasChildren()
{
return \count($this->children) > 0;
}
Expand All @@ -264,7 +264,7 @@ public function hasChildren(): bool
*
* @return int
*/
public function countChildren(): int
public function countChildren()
{
return \count($this->children);
}
Expand All @@ -279,7 +279,7 @@ public function countChildren(): int
*
* @return Node[]
*/
public function getDescendants(): array
public function getDescendants()
{
return $this->getDescendantsGeneric(false);
}
Expand All @@ -292,7 +292,7 @@ public function getDescendants(): array
*
* @return Node[]
*/
public function getDescendantsAndSelf(): array
public function getDescendantsAndSelf()
{
return $this->getDescendantsGeneric(true);
}
Expand All @@ -302,7 +302,7 @@ public function getDescendantsAndSelf(): array
*
* @return array
*/
protected function getDescendantsGeneric(bool $includeSelf): array
protected function getDescendantsGeneric(bool $includeSelf)
{
$descendants = $includeSelf ? [$this] : [];
foreach ($this->children as $childnode) {
Expand All @@ -327,7 +327,7 @@ protected function getDescendantsGeneric(bool $includeSelf): array
* @return Node[] Indexed array of nodes, sorted from the nearest
* one (or self) to the most remote one
*/
public function getAncestors(): array
public function getAncestors()
{
return $this->getAncestorsGeneric(false);
}
Expand All @@ -341,7 +341,7 @@ public function getAncestors(): array
*
* @return Node[] Indexed, sorted array of nodes: self, parent, grandparent, ...
*/
public function getAncestorsAndSelf(): array
public function getAncestorsAndSelf()
{
return $this->getAncestorsGeneric(true);
}
Expand All @@ -351,7 +351,7 @@ public function getAncestorsAndSelf(): array
*
* @return array
*/
protected function getAncestorsGeneric(bool $includeSelf): array
protected function getAncestorsGeneric($includeSelf)
{
if (null === $this->parent) {
return [];
Expand All @@ -367,7 +367,7 @@ protected function getAncestorsGeneric(bool $includeSelf): array
*
* @return array Associative array
*/
public function toArray(): array
public function toArray()
{
return $this->properties;
}
Expand Down

0 comments on commit 9e0397e

Please sign in to comment.