Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Add parameter type declarations #151

Merged
merged 1 commit into from
Jan 28, 2023
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ For a full diff see [`0.6.0...master`][0.6.0...master].

- Changed return type declaration of `NodeInterface::root()` from `self` to `static` ([#149]), by [@localheinz]
- Added a missing return type declaration to `NodeInterface::getSize()` ([#150]), by [@localheinz]
- Added parameter type declarations ([#151]), by [@localheinz]

## [`0.6.0`][0.6.0]

Expand Down Expand Up @@ -222,6 +223,7 @@ For a full diff see [`fcfd14e...v0.1.1`][fcfd14e...0.1.1].
[#148]: https://github.com/nicmart/Tree/pull/148
[#149]: https://github.com/nicmart/Tree/pull/149
[#150]: https://github.com/nicmart/Tree/pull/150
[#151]: https://github.com/nicmart/Tree/pull/151

[@asalazar-pley]: https://github.com/asalazar-pley
[@Djuki]: https://github.com/Djuki
Expand Down
12 changes: 0 additions & 12 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
<code>array</code>
<code>array</code>
</LessSpecificImplementedReturnType>
<MissingParamType>
<code>$value</code>
</MissingParamType>
<MixedArgument>
<code>$child</code>
</MixedArgument>
Expand Down Expand Up @@ -98,15 +95,6 @@
<ArgumentTypeCoercion>
<code>'Tree\Node\Node'</code>
</ArgumentTypeCoercion>
<InvalidArgument>
<code>'a'</code>
<code>'a'</code>
<code>'a'</code>
<code>'b'</code>
<code>'b'</code>
<code>'b'</code>
<code>'c'</code>
</InvalidArgument>
<InvalidDocblock>
<code>array[Node]</code>
</InvalidDocblock>
Expand Down
10 changes: 5 additions & 5 deletions src/Builder/NodeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function getNode(): NodeInterface
return $this->nodeStack[\count($this->nodeStack) - 1];
}

public function leaf($value = null): static
public function leaf(mixed $value = null): static
{
$this->getNode()->addChild(
$this->nodeInstanceByValue($value),
Expand All @@ -52,7 +52,7 @@ public function leaf($value = null): static
return $this;
}

public function leafs($value1 /* , $value2, ... */): static
public function leafs(mixed $value1 /* , $value2, ... */): static
{
foreach (\func_get_args() as $value) {
$this->leaf($value);
Expand All @@ -61,7 +61,7 @@ public function leafs($value1 /* , $value2, ... */): static
return $this;
}

public function tree($value = null): static
public function tree(mixed $value = null): static
{
$node = $this->nodeInstanceByValue($value);
$this->getNode()->addChild($node);
Expand All @@ -77,12 +77,12 @@ public function end(): ?static
return $this;
}

public function nodeInstanceByValue($value = null): NodeInterface
public function nodeInstanceByValue(mixed $value = null): NodeInterface
{
return new Node($value);
}

public function value($value): static
public function value(mixed $value): static
{
$this->getNode()->setValue($value);

Expand Down
20 changes: 5 additions & 15 deletions src/Builder/NodeBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,31 +32,23 @@ public function getNode(): NodeInterface;

/**
* Set the value of the underlaying node.
*
* @param mixed $value
*/
public function value($value): static;
public function value(mixed $value): static;

/**
* Add a leaf to the node.
*
* @param mixed $value The value of the leaf node
*/
public function leaf($value = null): static;
public function leaf(mixed $value = null): static;

/**
* Add several leafs to the node.
*
* @param mixed ...$value An arbitrary long list of values
*/
public function leafs($value /* , $value2, ... */): static;
public function leafs(mixed $value /* , $value2, ... */): static;

/**
* Add a child to the node enter in its scope.
*
* @param null $value
*/
public function tree($value = null): static;
public function tree(mixed $value = null): static;

/**
* Goes up to the parent node context.
Expand All @@ -66,8 +58,6 @@ public function end(): ?static;
/**
* Return a node instance set with the given value. Implementation can follow their own logic
* in choosing the NodeInterface implmentation taking into account the value.
*
* @param mixed $value
*/
public function nodeInstanceByValue($value = null): NodeInterface;
public function nodeInstanceByValue(mixed $value = null): NodeInterface;
}
2 changes: 1 addition & 1 deletion src/Node/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Node implements NodeInterface
* @param NodeInterface[] $children
*/
public function __construct(
$value = null,
mixed $value = null,
array $children = [],
) {
$this->setValue($value);
Expand Down
4 changes: 1 addition & 3 deletions src/Node/NodeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ interface NodeInterface
{
/**
* Set the value of the current node.
*
* @param mixed $value
*/
public function setValue($value): static;
public function setValue(mixed $value): static;

/**
* Get the current node value.
Expand Down
2 changes: 1 addition & 1 deletion src/Node/NodeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ trait NodeTrait
*/
private array $children = [];

public function setValue($value): static
public function setValue(mixed $value): static
{
$this->value = $value;

Expand Down