Skip to content

Commit

Permalink
[NodeTypeResolver] Ignore PHPStan internal error on PHPStanNodeScopeR…
Browse files Browse the repository at this point in the history
…esolver on NodeScopeResolver::processNodes() (#5586)

* [NodeTypeResolver] Ignore PHPStan internal error on PHPStanNodeScopeResolver on NodeScopeResolver::processNodes()

* fix phpstan

* fix reuse

* fix phpstan
  • Loading branch information
samsonasik committed Feb 8, 2024
1 parent 2aa1c38 commit 2194c6e
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\NodeTypeResolver\PHPStan\Scope;

use Throwable;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
Expand Down Expand Up @@ -121,7 +122,7 @@ public function processNodes(
$nodeCallback = function (Node $node, MutatingScope $mutatingScope) use (&$nodeCallback, $filePath): void {
if ($node instanceof FileWithoutNamespace) {
$node->setAttribute(AttributeKey::SCOPE, $mutatingScope);
$this->nodeScopeResolver->processNodes($node->stmts, $mutatingScope, $nodeCallback);
$this->nodeScopeResolverProcessNodes($node->stmts, $mutatingScope, $nodeCallback);

return;
}
Expand Down Expand Up @@ -197,7 +198,7 @@ public function processNodes(
}
};

$this->nodeScopeResolver->processNodes($stmts, $scope, $nodeCallback);
$this->nodeScopeResolverProcessNodes($stmts, $scope, $nodeCallback);

$nodeTraverser = new NodeTraverser();
$nodeTraverser->addVisitor(new WrappedNodeRestoringNodeVisitor());
Expand All @@ -207,6 +208,21 @@ public function processNodes(
return $stmts;
}

/**
* @param Stmt[] $stmts
* @param callable(Node $node, MutatingScope $scope): void $nodeCallback
*/
private function nodeScopeResolverProcessNodes(array $stmts, MutatingScope $mutatingScope, callable $nodeCallback): void
{
try {
$this->nodeScopeResolver->processNodes($stmts, $mutatingScope, $nodeCallback);
} catch (Throwable $throwable) {
if ($throwable->getMessage() !== 'Internal error.') {
throw $throwable;
}
}
}

public function hasUnreachableStatementNode(): bool
{
return $this->hasUnreachableStatementNode;
Expand Down Expand Up @@ -403,7 +419,7 @@ private function processTrait(Trait_ $trait, MutatingScope $mutatingScope, calla
$this->privatesAccessor->setPrivateProperty($traitScope, self::CONTEXT, $traitContext);

$trait->setAttribute(AttributeKey::SCOPE, $traitScope);
$this->nodeScopeResolver->processNodes($trait->stmts, $traitScope, $nodeCallback);
$this->nodeScopeResolverProcessNodes($trait->stmts, $traitScope, $nodeCallback);
$this->decorateTraitAttrGroups($trait, $traitScope);
}
}

0 comments on commit 2194c6e

Please sign in to comment.