Skip to content

Commit

Permalink
[Naming] Handle crash on VariableNaming::resolveBareFromNode() on unw…
Browse files Browse the repository at this point in the history
…rapNode() return null (#3136)

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
samsonasik and actions-user committed Dec 1, 2022
1 parent 39f43c0 commit 22b612e
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions rules/Naming/Naming/VariableNaming.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use PHPStan\Analyser\Scope;
use PHPStan\Type\ThisType;
use PHPStan\Type\Type;
use Rector\Core\Exception\NotImplementedYetException;
use Rector\Naming\Contract\AssignVariableNameResolverInterface;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\NodeTypeResolver;
Expand Down Expand Up @@ -119,33 +118,33 @@ private function resolveFromNode(Node $node): ?string

private function resolveBareFromNode(Node $node): ?string
{
$node = $this->unwrapNode($node);
$unwrappedNode = $this->unwrapNode($node);

foreach ($this->assignVariableNameResolvers as $assignVariableNameResolver) {
if ($assignVariableNameResolver->match($node)) {
return $assignVariableNameResolver->resolve($node);
}
if (! $unwrappedNode instanceof Node) {
return null;
}

if ($node !== null && ($node instanceof MethodCall || $node instanceof NullsafeMethodCall || $node instanceof StaticCall)) {
return $this->resolveFromMethodCall($node);
foreach ($this->assignVariableNameResolvers as $assignVariableNameResolver) {
if ($assignVariableNameResolver->match($unwrappedNode)) {
return $assignVariableNameResolver->resolve($unwrappedNode);
}
}

if ($node instanceof FuncCall) {
return $this->resolveFromNode($node->name);
if ($unwrappedNode instanceof MethodCall || $unwrappedNode instanceof NullsafeMethodCall || $unwrappedNode instanceof StaticCall) {
return $this->resolveFromMethodCall($unwrappedNode);
}

if (! $node instanceof Node) {
throw new NotImplementedYetException();
if ($unwrappedNode instanceof FuncCall) {
return $this->resolveFromNode($unwrappedNode->name);
}

$paramName = $this->nodeNameResolver->getName($node);
$paramName = $this->nodeNameResolver->getName($unwrappedNode);
if ($paramName !== null) {
return $paramName;
}

if ($node instanceof String_) {
return $node->value;
if ($unwrappedNode instanceof String_) {
return $unwrappedNode->value;
}

return null;
Expand Down

0 comments on commit 22b612e

Please sign in to comment.