Skip to content

Commit 21911ed

Browse files
committed
PreviousConnectingVisitor: Drop parent attribute
1 parent 2d12762 commit 21911ed

File tree

2 files changed

+1
-28
lines changed

2 files changed

+1
-28
lines changed

src/Ast/ExpressionFinder.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use PhpParser\Node\Expr\AssignOp;
1111
use PhpParser\Node\Expr\MethodCall;
1212
use PhpParser\Node\Expr\Variable;
13-
use PhpParser\Node\FunctionLike;
1413
use PhpParser\NodeFinder;
1514
use PHPStan\ShouldNotHappenException;
1615

@@ -147,15 +146,6 @@ private function findFirstPreviousOfNode(Node $node, callable $filter): ?Node
147146
return $this->findFirstPreviousOfNode($previousStatement, $filter);
148147
}
149148

150-
$parent = $node->getAttribute(PreviousConnectingVisitor::ATTRIBUTE_PARENT);
151-
if ($parent instanceof FunctionLike) {
152-
return null;
153-
}
154-
155-
if ($parent instanceof Node) {
156-
return $this->findFirstPreviousOfNode($parent, $filter);
157-
}
158-
159149
return null;
160150
}
161151

src/Ast/PreviousConnectingVisitor.php

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,11 @@
77
use PhpParser\Node;
88
use PhpParser\NodeVisitorAbstract;
99
use staabm\PHPStanDba\QueryReflection\DIContainerBridge;
10-
use function array_pop;
1110

1211
final class PreviousConnectingVisitor extends NodeVisitorAbstract
1312
{
14-
public const ATTRIBUTE_PARENT = 'dba-parent';
15-
1613
public const ATTRIBUTE_PREVIOUS = 'dba-previous';
1714

18-
/**
19-
* @var list<Node>
20-
*/
21-
private array $stack = [];
22-
2315
private ?Node $previous;
2416

2517
// a dummy property to force instantiation of DIContainerBridge
@@ -33,33 +25,24 @@ public function __construct(DIContainerBridge $dummyParameter)
3325

3426
public function beforeTraverse(array $nodes)
3527
{
36-
$this->stack = [];
3728
$this->previous = null;
3829

3930
return null;
4031
}
4132

4233
public function enterNode(Node $node)
4334
{
44-
if ([] !== $this->stack) {
45-
$node->setAttribute(self::ATTRIBUTE_PARENT, $this->stack[\count($this->stack) - 1]);
46-
}
47-
48-
if (null !== $this->previous && $this->previous->getAttribute(self::ATTRIBUTE_PARENT) === $node->getAttribute(self::ATTRIBUTE_PARENT)) {
35+
if (null !== $this->previous) {
4936
$node->setAttribute(self::ATTRIBUTE_PREVIOUS, $this->previous);
5037
}
5138

52-
$this->stack[] = $node;
53-
5439
return null;
5540
}
5641

5742
public function leaveNode(Node $node)
5843
{
5944
$this->previous = $node;
6045

61-
array_pop($this->stack);
62-
6346
return null;
6447
}
6548
}

0 commit comments

Comments
 (0)