Updated Rector to commit b5859be5c0af9089cc6fd2b007c24163db198334

b5859be5c0 [CodeQuality] Handle crash on Yield_ with first class callable on OptionalParametersAfterRequiredRector (#6529)
This commit is contained in:
Tomas Votruba 2024-12-05 03:03:10 +00:00
parent 3877f3d6f4
commit 55001041d1
3 changed files with 43 additions and 2 deletions

View File

@ -3,8 +3,11 @@
declare (strict_types=1); declare (strict_types=1);
namespace Rector\Application; namespace Rector\Application;
use PhpParser\Modifiers;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\ArrayItem; use PhpParser\Node\ArrayItem;
use PhpParser\Node\ClosureUse;
use PhpParser\Node\DeclareItem;
use PhpParser\Node\Expr; use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\CallLike; use PhpParser\Node\Expr\CallLike;
@ -15,13 +18,20 @@ use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\NullsafeMethodCall; use PhpParser\Node\Expr\NullsafeMethodCall;
use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\FunctionLike; use PhpParser\Node\FunctionLike;
use PhpParser\Node\PropertyItem;
use PhpParser\Node\StaticVar;
use PhpParser\Node\Stmt; use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Declare_;
use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Function_; use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\If_; use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\Static_;
use PhpParser\Node\Stmt\Switch_; use PhpParser\Node\Stmt\Switch_;
use PhpParser\Node\Stmt\TryCatch; use PhpParser\Node\Stmt\TryCatch;
use PhpParser\Node\Stmt\Use_;
use PhpParser\Node\UseItem;
use PHPStan\Analyser\MutatingScope; use PHPStan\Analyser\MutatingScope;
use Rector\Exception\ShouldNotHappenException; use Rector\Exception\ShouldNotHappenException;
use Rector\NodeAnalyzer\ScopeAnalyzer; use Rector\NodeAnalyzer\ScopeAnalyzer;
@ -91,9 +101,27 @@ final class ChangedNodeScopeRefresher
if ($node instanceof Expr) { if ($node instanceof Expr) {
return [new Expression($node)]; return [new Expression($node)];
} }
// moved from Expr/Stmt to directly under Node on PHPParser 5
if ($node instanceof ArrayItem) { if ($node instanceof ArrayItem) {
return [new Expression(new Array_([$node]))]; return [new Expression(new Array_([$node]))];
} }
if ($node instanceof ClosureUse) {
$closure = new Closure();
$closure->uses[] = $node;
return [new Expression($closure)];
}
if ($node instanceof DeclareItem) {
return [new Declare_([$node])];
}
if ($node instanceof PropertyItem) {
return [new Property(Modifiers::PUBLIC, [$node])];
}
if ($node instanceof StaticVar) {
return [new Static_([$node])];
}
if ($node instanceof UseItem) {
return [new Use_([$node])];
}
$errorMessage = \sprintf('Complete parent node of "%s" be a stmt.', \get_class($node)); $errorMessage = \sprintf('Complete parent node of "%s" be a stmt.', \get_class($node));
throw new ShouldNotHappenException($errorMessage); throw new ShouldNotHappenException($errorMessage);
} }

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api * @api
* @var string * @var string
*/ */
public const PACKAGE_VERSION = '2.0.0-rc2'; public const PACKAGE_VERSION = 'b5859be5c0af9089cc6fd2b007c24163db198334';
/** /**
* @api * @api
* @var string * @var string
*/ */
public const RELEASE_DATE = '2024-12-03 20:06:47'; public const RELEASE_DATE = '2024-12-05 10:00:50';
/** /**
* @var int * @var int
*/ */

View File

@ -28,6 +28,7 @@ use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\StaticPropertyFetch; use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Expr\Ternary; use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\Expr\Variable; use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Expr\Yield_;
use PhpParser\Node\Identifier; use PhpParser\Node\Identifier;
use PhpParser\Node\IntersectionType; use PhpParser\Node\IntersectionType;
use PhpParser\Node\Name; use PhpParser\Node\Name;
@ -260,6 +261,9 @@ final class PHPStanNodeScopeResolver
$this->processMatch($node, $mutatingScope); $this->processMatch($node, $mutatingScope);
return; return;
} }
if ($node instanceof Yield_) {
$this->processYield($node, $mutatingScope);
}
}; };
$this->nodeScopeResolverProcessNodes($stmts, $scope, $nodeCallback); $this->nodeScopeResolverProcessNodes($stmts, $scope, $nodeCallback);
$nodeTraverser = new NodeTraverser(); $nodeTraverser = new NodeTraverser();
@ -270,6 +274,15 @@ final class PHPStanNodeScopeResolver
$nodeTraverser->traverse($stmts); $nodeTraverser->traverse($stmts);
return $stmts; return $stmts;
} }
private function processYield(Yield_ $yield, MutatingScope $mutatingScope) : void
{
if ($yield->key instanceof Expr) {
$yield->key->setAttribute(AttributeKey::SCOPE, $mutatingScope);
}
if ($yield->value instanceof Expr) {
$yield->value->setAttribute(AttributeKey::SCOPE, $mutatingScope);
}
}
private function processMatch(Match_ $match, MutatingScope $mutatingScope) : void private function processMatch(Match_ $match, MutatingScope $mutatingScope) : void
{ {
$match->cond->setAttribute(AttributeKey::SCOPE, $mutatingScope); $match->cond->setAttribute(AttributeKey::SCOPE, $mutatingScope);