Skip to content

Commit

Permalink
[NodeTypeResolver] Reduce parent attribute usage on PHPStanNodeScopeR…
Browse files Browse the repository at this point in the history
…esolver (#3943)

* [NodeTypeResolver] Reduce parent attribute usage on PHPStanNodeScopeResolver

* increase kernel key

* clean up
  • Loading branch information
samsonasik committed May 24, 2023
1 parent 62ecc90 commit 3eadce1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use PhpParser\Node\Expr\AssignOp;
use PhpParser\Node\Expr\BinaryOp;
use PhpParser\Node\Expr\Cast;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\Expr\Variable;
Expand Down Expand Up @@ -47,7 +46,6 @@
use Rector\Core\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\NodeAnalyzer\ClassAnalyzer;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\Util\Reflection\PrivatesAccessor;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\Node\AttributeKey;
Expand Down Expand Up @@ -79,7 +77,6 @@ public function __construct(
private readonly ScopeFactory $scopeFactory,
private readonly PrivatesAccessor $privatesAccessor,
private readonly NodeNameResolver $nodeNameResolver,
private readonly BetterNodeFinder $betterNodeFinder,
private readonly ClassAnalyzer $classAnalyzer
) {
$this->nodeTraverser = new NodeTraverser();
Expand Down Expand Up @@ -236,25 +233,20 @@ public function processNodes(

private function setChildOfUnreachableStatementNodeAttribute(Stmt $stmt): void
{
if ($stmt->getAttribute(AttributeKey::IS_UNREACHABLE) === true) {
if ($stmt->getAttribute(AttributeKey::IS_UNREACHABLE) !== true) {
return;
}

$parentStmt = $stmt->getAttribute(AttributeKey::PARENT_NODE);
if (! $parentStmt instanceof Node) {
if (! $stmt instanceof StmtsAwareInterface) {
return;
}

if ($parentStmt instanceof Closure) {
$parentStmt = $this->betterNodeFinder->resolveCurrentStatement($parentStmt);
}

if (! $parentStmt instanceof Stmt) {
if ($stmt->stmts === null) {
return;
}

if ($parentStmt->getAttribute(AttributeKey::IS_UNREACHABLE) === true) {
$stmt->setAttribute(AttributeKey::IS_UNREACHABLE, true);
foreach ($stmt->stmts as $childStmt) {
$childStmt->setAttribute(AttributeKey::IS_UNREACHABLE, true);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Kernel/RectorKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class RectorKernel
/**
* @var string
*/
private const CACHE_KEY = 'v24';
private const CACHE_KEY = 'v25';

private ContainerInterface|null $container = null;

Expand Down

0 comments on commit 3eadce1

Please sign in to comment.