Skip to content

Commit

Permalink
Update phpdoc to fix PHPStan errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Dec 14, 2019
1 parent 8ba6d21 commit c7ed6a2
Show file tree
Hide file tree
Showing 21 changed files with 74 additions and 40 deletions.
1 change: 1 addition & 0 deletions grumphp.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ imports:
- { resource: vendor/drupol/php-conventions/config/php71/grumphp.yml }

parameters:
tasks.phpstan.config: phpstan.neon
extra_tasks:
phpspec:
verbose: true
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
checkMissingIterableValueType: false
ignoreErrors:
- '#Method drupol\\phptree\\Node\\MerkleNode::normalize\(\) should return drupol\\phptree\\Node\\MerkleNodeInterface but returns drupol\\phptree\\Node\\NodeInterface.#'
- '#Anonymous function should return drupol\\phptree\\Node\\MerkleNodeInterface but returns drupol\\phptree\\Node\\NodeInterface.#'
2 changes: 1 addition & 1 deletion src/Builder/BuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
interface BuilderInterface
{
/**
* @param iterable<NodeInterface> $nodes
* @param iterable<mixed> $nodes
*
* @return \drupol\phptree\Node\NodeInterface|null
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Exporter/Ascii.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function export(NodeInterface $node): string
* @param \drupol\phptree\Node\NodeInterface $node
* The node
*
* @return array
* @return array<int, mixed>
* The tree exported into an array
*/
private function doExportAsArray(NodeInterface $node): array
Expand Down
3 changes: 1 addition & 2 deletions src/Exporter/Graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public function export(NodeInterface $node): OriginalGraph
$this->graph = new OriginalGraph();

foreach ($node->all() as $node_visited) {
/** @var int $vertexId */
$vertexFrom = $this->createVertex($node_visited);

foreach ($node_visited->children() as $child) {
Expand Down Expand Up @@ -65,7 +64,7 @@ protected function createVertex(NodeInterface $node): Vertex

if ($node instanceof AttributeNodeInterface) {
foreach ($node->getAttributes() as $key => $value) {
$vertex->setAttribute($key, $value);
$vertex->setAttribute((string) $key, $value);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/Exporter/Gv.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function setDirected(bool $directed = true): self
/**
* Set the graph attributes.
*
* @param array $attributes
* @param array<mixed, mixed> $attributes
* The graph attributes.
*
* @return \drupol\phptree\Exporter\Gv
Expand All @@ -130,7 +130,7 @@ public function setGraphAttributes(array $attributes): self
/**
* Converts an attributes array to string.
*
* @param array $attributes
* @param array<mixed, mixed> $attributes
* The attributes.
*
* @return string
Expand All @@ -155,7 +155,7 @@ static function ($key, $value) {
* @param \drupol\phptree\Node\NodeInterface $node
* The root node.
*
* @return Generator
* @return Generator<NodeInterface, NodeInterface>
* Yield the parent and child node.
*/
protected function findEdges(NodeInterface $node): iterable
Expand Down Expand Up @@ -218,7 +218,7 @@ protected function getHash(NodeInterface $node): string
* @param \drupol\phptree\Node\NodeInterface $node
* The node interface.
*
* @return array
* @return array<mixed, mixed>
* The attributes as an array.
*/
protected function getNodeAttributes(NodeInterface $node): array
Expand Down
2 changes: 1 addition & 1 deletion src/Importer/SimpleArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function import($data): NodeInterface
/**
* Convert an array into a tree.
*
* @param array $data
* @param array<string, mixed> $data
*
* @return \drupol\phptree\Node\NodeInterface
* The tree
Expand Down
6 changes: 3 additions & 3 deletions src/Importer/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function import($data): NodeInterface
* @param mixed $arguments
* The arguments
*
* @return \drupol\phptree\Node\Node
* @return \drupol\phptree\Node\NodeInterface
* The node
*/
protected function createNode($arguments): NodeInterface
Expand All @@ -47,10 +47,10 @@ protected function createNode($arguments): NodeInterface
* @param string $subject
* The subject string
*
* @return array|bool
* @return array<int, mixed>
* The array
*/
private function parse(string $subject)
private function parse(string $subject): array
{
$result = [];

Expand Down
2 changes: 1 addition & 1 deletion src/Node/AttributeNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AttributeNode extends NaryNode implements AttributeNodeInterface
/**
* ValueNode constructor.
*
* @param array $attributes
* @param array<int|string, mixed> $attributes
* @param int|null $capacity
* @param \drupol\phptree\Traverser\TraverserInterface|null $traverser
* @param \drupol\phptree\Node\NodeInterface|null $parent
Expand Down
4 changes: 2 additions & 2 deletions src/Node/AttributeNodeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function getAttribute(string $key);
/**
* Get the attributes.
*
* @return Traversable
* @return Traversable<int|string, mixed>
* The attributes.
*/
public function getAttributes(): Traversable;
Expand All @@ -45,7 +45,7 @@ public function setAttribute(string $key, $value): AttributeNodeInterface;
/**
* Set the attributes.
*
* @param Traversable $attributes
* @param Traversable<int|string, mixed> $attributes
* The attributes.
*
* @return \drupol\phptree\Node\AttributeNodeInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Node/MerkleNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function normalize(): MerkleNodeInterface
{
return array_reduce(
$this->modifiers,
static function (NodeInterface $tree, ModifierInterface $modifier): NodeInterface {
static function (MerkleNodeInterface $tree, ModifierInterface $modifier): MerkleNodeInterface {
return $modifier->modify($tree);
},
$this->clone()
Expand Down
21 changes: 15 additions & 6 deletions src/Node/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function getAncestors(): Traversable
}

/**
* {@inheritdoc}
* @return Traversable<\drupol\phptree\Node\NodeInterface>
*/
public function getIterator()
{
Expand Down Expand Up @@ -244,23 +244,30 @@ public function level(int $level): Traversable
}

/**
* {@inheritdoc}
* @param mixed $offset
*
* @return bool
*/
public function offsetExists($offset)
{
return $this->storage()->getChildren()->offsetExists($offset);
}

/**
* {@inheritdoc}
* @param mixed $offset
*
* @return \drupol\phptree\Node\NodeInterface
*/
public function offsetGet($offset)
{
return $this->storage()->getChildren()->offsetGet($offset);
}

/**
* {@inheritdoc}
* @param mixed $offset
* @param mixed $value
*
* @return void
*/
public function offsetSet($offset, $value): void
{
Expand All @@ -275,9 +282,11 @@ public function offsetSet($offset, $value): void
}

/**
* {@inheritdoc}
* @param mixed $offset
*
* @return void
*/
public function offsetUnset($offset): void
public function offsetUnset($offset)
{
$this->storage()->getChildren()->offsetUnset($offset);
}
Expand Down
11 changes: 7 additions & 4 deletions src/Node/NodeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

/**
* Interface NodeInterface.
*
* @template-extends ArrayAccess<int, mixed>
* @template-extends IteratorAggregate<int, mixed>
*/
interface NodeInterface extends ArrayAccess, Countable, IteratorAggregate
{
Expand All @@ -28,15 +31,15 @@ public function add(NodeInterface ...$node): NodeInterface;
/**
* Get all the nodes of a tree including the parent node itself.
*
* @return Traversable
* @return Traversable<\drupol\phptree\Node\NodeInterface>
* The node.
*/
public function all(): Traversable;

/**
* Get the children.
*
* @return Traversable
* @return Traversable<\drupol\phptree\Node\NodeInterface>
* The children
*/
public function children(): Traversable;
Expand Down Expand Up @@ -90,7 +93,7 @@ public function find(NodeInterface $node): ?NodeInterface;
/**
* Get the ancestors of a node.
*
* @return Traversable
* @return Traversable<\drupol\phptree\Node\NodeInterface>
* The ancestors
*/
public function getAncestors(): Traversable;
Expand All @@ -106,7 +109,7 @@ public function getParent(): ?NodeInterface;
/**
* Get the node's sibblings.
*
* @return Traversable
* @return Traversable<\drupol\phptree\Node\NodeInterface>
* The sibblings
*/
public function getSibblings(): Traversable;
Expand Down
2 changes: 1 addition & 1 deletion src/Node/TrieNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class TrieNode extends KeyValueNode
*/
public function add(NodeInterface ...$nodes): NodeInterface
{
/** @var \drupol\phptree\Node\KeyValueNodeInterface $node */
foreach ($nodes as $node) {
$data = $node->getValue();

Expand All @@ -32,6 +31,7 @@ public function add(NodeInterface ...$nodes): NodeInterface
} else {
$nodes = [$node->getValue()];

/** @var \drupol\phptree\Node\KeyValueNodeInterface $ancestor */
foreach ($node->getAncestors() as $ancestor) {
$nodes[] = $ancestor->getValue();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Storage/NodeStorageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface NodeStorageInterface extends StorageInterface
/**
* Get the children.
*
* @return ArrayObject
* @return ArrayObject<int, NodeInterface>
*/
public function getChildren();

Expand Down
25 changes: 18 additions & 7 deletions src/Storage/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
* Class Storage.
*
* @internal
*
* @implements ArrayAccess<string, mixed>
*/
abstract class Storage implements ArrayAccess, StorageInterface
{
/**
* @var ArrayObject
* @var ArrayObject<string, mixed>
*/
private $storage;

Expand Down Expand Up @@ -56,33 +58,42 @@ public function get($key)
}

/**
* {@inheritdoc}
* @param mixed $offset
*
* @return bool
*/
public function offsetExists($offset)
{
return $this->storage->offsetExists($offset);
}

/**
* {@inheritdoc}
* @param mixed $offset
*
* @return mixed
*/
public function offsetGet($offset)
{
return $this->storage->offsetGet($offset);
}

/**
* {@inheritdoc}
* @param mixed $offset
* @param mixed $value
*
* @return void
*/
public function offsetSet($offset, $value): void
public function offsetSet($offset, $value)
{
$this->storage->offsetSet($offset, $value);
}

/**
* {@inheritdoc}
* @param mixed $offset
*
* @return void
*/
public function offsetUnset($offset): void
public function offsetUnset($offset)
{
$this->storage->offsetUnset($offset);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Storage/StorageInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ public function get($key);
*
* @return StorageInterface
*/
public function set($key, $value): self;
public function set($key, $value): StorageInterface;
}
4 changes: 3 additions & 1 deletion src/Traverser/InOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public function traverse(NodeInterface $node): Traversable
}

/**
* {@inheritdoc}
* @param NodeInterface $node
*
* @return Traversable<NodeInterface>
*/
private function doTraverse(NodeInterface $node): Traversable
{
Expand Down
4 changes: 3 additions & 1 deletion src/Traverser/PostOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public function traverse(NodeInterface $node): Traversable
}

/**
* {@inheritdoc}
* @param NodeInterface $node
*
* @return Traversable<NodeInterface>
*/
private function doTraverse(NodeInterface $node): Traversable
{
Expand Down
4 changes: 3 additions & 1 deletion src/Traverser/PreOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public function traverse(NodeInterface $node): Traversable
}

/**
* {@inheritdoc}
* @param NodeInterface $node
*
* @return Traversable<NodeInterface>
*/
private function doTraverse(NodeInterface $node): Traversable
{
Expand Down
2 changes: 1 addition & 1 deletion src/Traverser/TraverserInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface TraverserInterface
* @param \drupol\phptree\Node\NodeInterface $node
* The node
*
* @return Generator|NodeInterface[]|Traversable
* @return Generator|Traversable<NodeInterface>
*/
public function traverse(NodeInterface $node): Traversable;
}

0 comments on commit c7ed6a2

Please sign in to comment.