Skip to content

Commit

Permalink
Fix PHPStan problems and be explicit
Browse files Browse the repository at this point in the history
  • Loading branch information
szepeviktor authored and localheinz committed Oct 4, 2022
1 parent 65589df commit e38c886
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 61 deletions.
54 changes: 5 additions & 49 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="4.27.0@faf106e717c37b8c81721845dba9de3d8deed8ff">
<file src="src/Builder/NodeBuilder.php">
<MissingParamType occurrences="1">
<code>$value1</code>
</MissingParamType>
<MissingReturnType occurrences="3">
<code>emptyStack</code>
<code>popNode</code>
Expand All @@ -19,19 +16,6 @@
<code>$value1</code>
</ParamNameMismatch>
</file>
<file src="src/Builder/NodeBuilderInterface.php">
<InvalidClass occurrences="1">
<code>NodebuilderInterface</code>
</InvalidClass>
<MissingParamType occurrences="1">
<code>$value</code>
</MissingParamType>
</file>
<file src="src/Node/Node.php">
<PropertyNotSetInConstructor occurrences="1">
<code>Node</code>
</PropertyNotSetInConstructor>
</file>
<file src="src/Node/NodeInterface.php">
<MissingReturnType occurrences="2">
<code>accept</code>
Expand All @@ -42,9 +26,6 @@
<ArgumentTypeCoercion occurrences="1">
<code>$heights</code>
</ArgumentTypeCoercion>
<DocblockTypeContradiction occurrences="1">
<code>null === $this-&gt;getParent()</code>
</DocblockTypeContradiction>
<MissingParamType occurrences="1">
<code>$value</code>
</MissingParamType>
Expand All @@ -66,15 +47,11 @@
<MixedReturnTypeCoercion occurrences="1">
<code>getAncestorsAndSelf</code>
</MixedReturnTypeCoercion>
<MoreSpecificReturnType occurrences="1">
<code>getNeighborsAndSelf</code>
</MoreSpecificReturnType>
<PossiblyNullPropertyAssignmentValue occurrences="1">
<code>$parent</code>
</PossiblyNullPropertyAssignmentValue>
<RedundantConditionGivenDocblockType occurrences="1">
<code>null !== $this-&gt;getParent()</code>
</RedundantConditionGivenDocblockType>
<PossiblyNullReference occurrences="3">
<code>getChildren</code>
<code>getChildren</code>
<code>getDepth</code>
</PossiblyNullReference>
<UndefinedInterfaceMethod occurrences="1">
<code>getSize</code>
</UndefinedInterfaceMethod>
Expand Down Expand Up @@ -128,11 +105,6 @@
<PossiblyNullReference occurrences="1">
<code>leaf</code>
</PossiblyNullReference>
<PropertyNotSetInConstructor occurrences="3">
<code>$builder</code>
<code>NodeBuilderTest</code>
<code>NodeBuilderTest</code>
</PropertyNotSetInConstructor>
</file>
<file src="tests/Node/NodeTest.php">
<MissingReturnType occurrences="21">
Expand Down Expand Up @@ -192,10 +164,6 @@
<code>removeChild</code>
<code>removeChild</code>
</MixedMethodCall>
<PropertyNotSetInConstructor occurrences="2">
<code>NodeTest</code>
<code>NodeTest</code>
</PropertyNotSetInConstructor>
<UnusedVariable occurrences="4">
<code>$child2</code>
<code>$child2</code>
Expand All @@ -214,10 +182,6 @@
<code>testWalkTreeWithOneNode</code>
<code>testWalkTreeWithTwoNodes</code>
</MissingReturnType>
<PropertyNotSetInConstructor occurrences="2">
<code>PostOrderVisitorTest</code>
<code>PostOrderVisitorTest</code>
</PropertyNotSetInConstructor>
</file>
<file src="tests/Visitor/PreOrderVisitorTest.php">
<ArgumentTypeCoercion occurrences="1">
Expand All @@ -230,10 +194,6 @@
<code>testWalkTreeWithOneNode</code>
<code>testWalkTreeWithTwoNodes</code>
</MissingReturnType>
<PropertyNotSetInConstructor occurrences="2">
<code>PreOrderVisitorTest</code>
<code>PreOrderVisitorTest</code>
</PropertyNotSetInConstructor>
</file>
<file src="tests/Visitor/YieldVisitorTest.php">
<MissingReturnType occurrences="2">
Expand All @@ -244,10 +204,6 @@
<code>addChild</code>
<code>addChild</code>
</MixedMethodCall>
<PropertyNotSetInConstructor occurrences="2">
<code>YieldVisitorTest</code>
<code>YieldVisitorTest</code>
</PropertyNotSetInConstructor>
<UnusedVariable occurrences="1">
<code>$d</code>
</UnusedVariable>
Expand Down
6 changes: 3 additions & 3 deletions src/Builder/NodeBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getNode();
*
* @param mixed $value
*
* @return NodebuilderInterface The current instance
* @return NodeBuilderInterface The current instance
*/
public function value($value);

Expand All @@ -55,11 +55,11 @@ public function leaf($value = null);
/**
* Add several leafs to the node.
*
* @param $value, ... An arbitrary long list of values
* @param mixed ...$value An arbitrary long list of values
*
* @return NodeBuilderInterface The current instance
*/
public function leafs($value);
public function leafs($value /*, $value2, ... */);

/**
* Add a child to the node enter in its scope.
Expand Down
6 changes: 4 additions & 2 deletions src/Node/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ public function __construct($value = null, array $children = [])
{
$this->setValue($value);

if (!empty($children)) {
$this->setChildren($children);
if ([] === $children) {
return;
}

$this->setChildren($children);
}
}
4 changes: 2 additions & 2 deletions src/Node/NodeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function setParent(?self $parent = null);
/**
* Return the parent node.
*
* @return NodeInterface
* @return null|NodeInterface
*/
public function getParent();

Expand Down Expand Up @@ -115,7 +115,7 @@ public function getNeighbors();
/**
* Returns all neighboring nodes, including the current node.
*
* @return Node[]
* @return NodeInterface[]
*/
public function getNeighborsAndSelf();

Expand Down
8 changes: 3 additions & 5 deletions src/Node/NodeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ trait NodeTrait
private $value;

/**
* parent.
*
* @var NodeInterface
* @var null|NodeInterface
*/
private $parent;

Expand Down Expand Up @@ -106,7 +104,7 @@ public function getAncestors()
$parents = [];
$node = $this;

while ($parent = $node->getParent()) {
while (($parent = $node->getParent()) instanceof NodeInterface) {
\array_unshift($parents, $parent);
$node = $parent;
}
Expand Down Expand Up @@ -166,7 +164,7 @@ public function root()
{
$node = $this;

while ($parent = $node->getParent()) {
while (($parent = $node->getParent()) instanceof NodeInterface) {
$node = $parent;
}

Expand Down

0 comments on commit e38c886

Please sign in to comment.