Skip to content

Commit a32954a

Browse files
authored
Merge pull request #151 from nicmart/fix/parameter
Fix: Add parameter type declarations
2 parents 0c6f21f + 8beacce commit a32954a

7 files changed

+15
-37
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ For a full diff see [`0.6.0...master`][0.6.0...master].
1212

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

1617
## [`0.6.0`][0.6.0]
1718

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

226228
[@asalazar-pley]: https://github.com/asalazar-pley
227229
[@Djuki]: https://github.com/Djuki

psalm-baseline.xml

-12
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@
3131
<code>array</code>
3232
<code>array</code>
3333
</LessSpecificImplementedReturnType>
34-
<MissingParamType>
35-
<code>$value</code>
36-
</MissingParamType>
3734
<MixedArgument>
3835
<code>$child</code>
3936
</MixedArgument>
@@ -98,15 +95,6 @@
9895
<ArgumentTypeCoercion>
9996
<code>'Tree\Node\Node'</code>
10097
</ArgumentTypeCoercion>
101-
<InvalidArgument>
102-
<code>'a'</code>
103-
<code>'a'</code>
104-
<code>'a'</code>
105-
<code>'b'</code>
106-
<code>'b'</code>
107-
<code>'b'</code>
108-
<code>'c'</code>
109-
</InvalidArgument>
11098
<InvalidDocblock>
11199
<code>array[Node]</code>
112100
</InvalidDocblock>

src/Builder/NodeBuilder.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function getNode(): NodeInterface
4343
return $this->nodeStack[\count($this->nodeStack) - 1];
4444
}
4545

46-
public function leaf($value = null): static
46+
public function leaf(mixed $value = null): static
4747
{
4848
$this->getNode()->addChild(
4949
$this->nodeInstanceByValue($value),
@@ -52,7 +52,7 @@ public function leaf($value = null): static
5252
return $this;
5353
}
5454

55-
public function leafs($value1 /* , $value2, ... */): static
55+
public function leafs(mixed $value1 /* , $value2, ... */): static
5656
{
5757
foreach (\func_get_args() as $value) {
5858
$this->leaf($value);
@@ -61,7 +61,7 @@ public function leafs($value1 /* , $value2, ... */): static
6161
return $this;
6262
}
6363

64-
public function tree($value = null): static
64+
public function tree(mixed $value = null): static
6565
{
6666
$node = $this->nodeInstanceByValue($value);
6767
$this->getNode()->addChild($node);
@@ -77,12 +77,12 @@ public function end(): ?static
7777
return $this;
7878
}
7979

80-
public function nodeInstanceByValue($value = null): NodeInterface
80+
public function nodeInstanceByValue(mixed $value = null): NodeInterface
8181
{
8282
return new Node($value);
8383
}
8484

85-
public function value($value): static
85+
public function value(mixed $value): static
8686
{
8787
$this->getNode()->setValue($value);
8888

src/Builder/NodeBuilderInterface.php

+5-15
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,23 @@ public function getNode(): NodeInterface;
3232

3333
/**
3434
* Set the value of the underlaying node.
35-
*
36-
* @param mixed $value
3735
*/
38-
public function value($value): static;
36+
public function value(mixed $value): static;
3937

4038
/**
4139
* Add a leaf to the node.
42-
*
43-
* @param mixed $value The value of the leaf node
4440
*/
45-
public function leaf($value = null): static;
41+
public function leaf(mixed $value = null): static;
4642

4743
/**
4844
* Add several leafs to the node.
49-
*
50-
* @param mixed ...$value An arbitrary long list of values
5145
*/
52-
public function leafs($value /* , $value2, ... */): static;
46+
public function leafs(mixed $value /* , $value2, ... */): static;
5347

5448
/**
5549
* Add a child to the node enter in its scope.
56-
*
57-
* @param null $value
5850
*/
59-
public function tree($value = null): static;
51+
public function tree(mixed $value = null): static;
6052

6153
/**
6254
* Goes up to the parent node context.
@@ -66,8 +58,6 @@ public function end(): ?static;
6658
/**
6759
* Return a node instance set with the given value. Implementation can follow their own logic
6860
* in choosing the NodeInterface implmentation taking into account the value.
69-
*
70-
* @param mixed $value
7161
*/
72-
public function nodeInstanceByValue($value = null): NodeInterface;
62+
public function nodeInstanceByValue(mixed $value = null): NodeInterface;
7363
}

src/Node/Node.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Node implements NodeInterface
2020
* @param NodeInterface[] $children
2121
*/
2222
public function __construct(
23-
$value = null,
23+
mixed $value = null,
2424
array $children = [],
2525
) {
2626
$this->setValue($value);

src/Node/NodeInterface.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ interface NodeInterface
2222
{
2323
/**
2424
* Set the value of the current node.
25-
*
26-
* @param mixed $value
2725
*/
28-
public function setValue($value): static;
26+
public function setValue(mixed $value): static;
2927

3028
/**
3129
* Get the current node value.

src/Node/NodeTrait.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ trait NodeTrait
2626
*/
2727
private array $children = [];
2828

29-
public function setValue($value): static
29+
public function setValue(mixed $value): static
3030
{
3131
$this->value = $value;
3232

0 commit comments

Comments
 (0)