Skip to content

Commit

Permalink
Update the PHPDoc.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Dec 7, 2018
1 parent 7420179 commit 298d868
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 21 deletions.
6 changes: 4 additions & 2 deletions src/Node/KeyValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
namespace drupol\phptree\Node;

/**
* Class Node
* Class KeyValueNode
*/
class KeyValueNode extends ValueNode implements KeyValueNodeInterface
{
/**
* @var mixed|null
* The key property.
*
* @var string|mixed|int|null
*/
private $key;

Expand Down
5 changes: 4 additions & 1 deletion src/Node/KeyValueNodeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
namespace drupol\phptree\Node;

/**
* Class KeyValueNodeInterface
* Interface KeyValueNodeInterface
*/
interface KeyValueNodeInterface extends ValueNodeInterface
{
/**
* Get the node key.
*
* @return string|mixed|int|null
* The key value.
*/
public function getKey();
}
6 changes: 4 additions & 2 deletions src/Node/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
class Node implements NodeInterface
{
/**
* The storage property.
*
* @var array
*/
protected $storage;
Expand Down Expand Up @@ -75,7 +77,7 @@ public function getParent(): ?NodeInterface
/**
* {@inheritdoc}
*/
public function children():array
public function children(): array
{
return $this->storage['children'];
}
Expand Down Expand Up @@ -139,7 +141,7 @@ function ($child) use ($node) {
/**
* {@inheritdoc}
*/
public function degree():int
public function degree(): int
{
return \count($this->storage['children']);
}
Expand Down
53 changes: 43 additions & 10 deletions src/Node/NodeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,63 +5,96 @@
namespace drupol\phptree\Node;

/**
* Class NodeInterface
* Interface NodeInterface
*/
interface NodeInterface extends \Countable
{
/**
* @return \drupol\phptree\Node\NodeInterface|null
* Get the parent node.
*
* @return NodeInterface|null
* The parent node if any, null otherwise.
*/
public function getParent(): ?NodeInterface;

/**
* @param \drupol\phptree\Node\NodeInterface $node
* Set the parent.
*
* @param NodeInterface $node
* The parent node.
*
* @return \drupol\phptree\Node\NodeInterface
* @return NodeInterface
* The node.
*/
public function setParent(NodeInterface $node): NodeInterface;

/**
* @param \drupol\phptree\Node\NodeInterface ...$node
* The node to add.
*
* @param NodeInterface ...$node
* The node to add.
*
* @return \drupol\phptree\Node\NodeInterface
* @return NodeInterface
* The node.
*/
public function add(NodeInterface ...$node): NodeInterface;

/**
* @param \drupol\phptree\Node\NodeInterface ...$node
* Remove children.
*
* @return \drupol\phptree\Node\NodeInterface
* @param NodeInterface ...$node
* The node to remove.
*
* @return NodeInterface
* The node.
*/
public function remove(NodeInterface ...$node): NodeInterface;

/**
* Get the children.
*
* @return NodeInterface[]
* The children.
*/
public function children(): array;

/**
* Check if the node is a leaf.
*
* @return bool
* True if it's a leaf, false otherwise.
*/
public function isLeaf(): bool;

/**
* Check if the node is the root node.
*
* @return bool
* True if it's a root node, false otherwise.
*/
public function isRoot(): bool;

/**
* @return array
* Get the ancestors of a node.
*
* @return NodeInterface[]
* The array of ancestors.
*/
public function getAncestors(): array;

/**
* @return array
* Get the node's sibblings.
*
* @return NodeInterface[]
* The array of sibblings.
*/
public function getSibblings(): array;

/**
* The number of children a node has.
*
* @return int
* The amound of children.
*/
public function degree(): int;
}
2 changes: 1 addition & 1 deletion src/Node/ValueNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class ValueNode extends Node implements ValueNodeInterface
{
/**
* @var mixed|null
* @var string|mixed|null
*/
private $value;

Expand Down
5 changes: 4 additions & 1 deletion src/Node/ValueNodeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@
namespace drupol\phptree\Node;

/**
* Class ValueNodeInterface
* Interface ValueNodeInterface
*/
interface ValueNodeInterface extends NodeInterface
{
/**
* Get the node value.
*
* @return string|mixed|null
* The node value.
*/
public function getValue();
}
9 changes: 5 additions & 4 deletions src/Visitor/AbstractVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@

use drupol\phptree\Node\NodeInterface;

abstract class AbstractVisitor
/**
* Class AbstractVisitor
*/
abstract class AbstractVisitor implements VisitorInterface
{
/**
* @param \drupol\phptree\Node\NodeInterface $node
*
* @return \Traversable
* {@inheritdoc}
*/
abstract public function traverse(NodeInterface $node): \Traversable;
}
21 changes: 21 additions & 0 deletions src/Visitor/VisitorInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace drupol\phptree\Visitor;

use drupol\phptree\Node\NodeInterface;

/**
* Interface VisitorInterface
*/
interface VisitorInterface
{
/**
* Traverse the tree.
*
* @param \drupol\phptree\Node\NodeInterface $node
* The node.
*
* @return \Traversable
*/
public function traverse(NodeInterface $node): \Traversable;
}

0 comments on commit 298d868

Please sign in to comment.