Skip to content

Commit

Permalink
[CodeQuality] Handle crash on first class callable in call (#6556)
Browse files Browse the repository at this point in the history
* [CodeQuality] Handle crash on first class callable in call

* fix
  • Loading branch information
samsonasik authored Dec 11, 2024
1 parent bf5270a commit cce5097
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\CodeQuality\Rector\ClassMethod\OptionalParametersAfterRequiredRector\Fixture;

final class SkipFirstClassCallableInCall
{
public function getSubscribedEvents()
{
return $this->textElement(...)->execute(...);
}

public function textElement()
{
}
}
12 changes: 11 additions & 1 deletion src/NodeTypeResolver/PHPStan/Scope/PHPStanNodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Rector\NodeTypeResolver\PHPStan\Scope;

use Error;
use PHPStan\Node\Printer\Printer;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\ArrayItem;
Expand Down Expand Up @@ -88,6 +87,8 @@
use PHPStan\Analyser\MutatingScope;
use PHPStan\Analyser\NodeScopeResolver;
use PHPStan\Analyser\ScopeContext;
use PHPStan\Node\MethodCallableNode;
use PHPStan\Node\Printer\Printer;
use PHPStan\Node\UnreachableStatementNode;
use PHPStan\Node\VirtualNode;
use PHPStan\Parser\ParserErrorsException;
Expand Down Expand Up @@ -384,6 +385,15 @@ public function processNodes(
$node->cond->setAttribute(AttributeKey::SCOPE, $mutatingScope);
return;
}

if ($node instanceof MethodCallableNode) {
$node->getOriginalNode()
->setAttribute(AttributeKey::SCOPE, $mutatingScope);
$node->getOriginalNode()
->var->setAttribute(AttributeKey::SCOPE, $mutatingScope);
$node->getOriginalNode()
->name->setAttribute(AttributeKey::SCOPE, $mutatingScope);
}
};

try {
Expand Down

0 comments on commit cce5097

Please sign in to comment.