diff --git a/rules/CodingStyle/Rector/ClassMethod/FuncGetArgsToVariadicParamRector.php b/rules/CodingStyle/Rector/ClassMethod/FuncGetArgsToVariadicParamRector.php index 538f9078e39..4c65cf07b23 100644 --- a/rules/CodingStyle/Rector/ClassMethod/FuncGetArgsToVariadicParamRector.php +++ b/rules/CodingStyle/Rector/ClassMethod/FuncGetArgsToVariadicParamRector.php @@ -4,21 +4,16 @@ declare (strict_types=1); namespace Rector\CodingStyle\Rector\ClassMethod; use PhpParser\Node; -use PhpParser\Node\Arg; -use PhpParser\Node\Expr; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\Variable; -use PhpParser\Node\FunctionLike; use PhpParser\Node\Param; -use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Function_; use Rector\Core\Rector\AbstractRector; use Rector\Core\ValueObject\PhpVersionFeature; -use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -59,20 +54,23 @@ CODE_SAMPLE if ($node->params !== []) { return null; } - $assign = $this->matchFuncGetArgsVariableAssign($node); - if (!$assign instanceof Assign) { + /** @var Expression|null $expression */ + $expression = $this->matchFuncGetArgsVariableAssign($node); + if (!$expression instanceof Expression) { return null; } + /** @var Assign $assign */ + $assign = $expression->expr; if ($assign->var instanceof Variable) { $variableName = $this->getName($assign->var); if ($variableName === null) { return null; } - return $this->removeOrChangeAssignToVariable($node, $assign, $variableName); + $this->removeNode($assign); + return $this->applyVariadicParams($node, $variableName); } - $variableName = 'args'; $assign->expr = new Variable('args'); - return $this->applyVariadicParams($node, $variableName); + return $this->applyVariadicParams($node, 'args'); } public function provideMinPhpVersion() : int { @@ -92,34 +90,6 @@ CODE_SAMPLE $node->params[] = $param; return $node; } - /** - * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $node - * @return \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure|null - */ - private function removeOrChangeAssignToVariable($node, Assign $assign, string $variableName) - { - $parentNode = $assign->getAttribute(AttributeKey::PARENT_NODE); - if ($parentNode instanceof Expression) { - $this->removeNode($assign); - return $this->applyVariadicParams($node, $variableName); - } - $variable = $assign->var; - /** @var ClassMethod|Function_|Closure $functionLike */ - $functionLike = $this->betterNodeFinder->findParentType($parentNode, FunctionLike::class); - /** @var Stmt[] $stmts */ - $stmts = $functionLike->getStmts(); - $this->traverseNodesWithCallable($stmts, function (Node $node) use($assign, $variable) : ?Expr { - if (!$this->nodeComparator->areNodesEqual($node, $assign)) { - return null; - } - if ($node instanceof Arg) { - return null; - } - return $variable; - }); - $this->applyVariadicParams($functionLike, $variableName); - return $node; - } /** * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike */ @@ -135,28 +105,35 @@ CODE_SAMPLE if ($node->params !== []) { return \false; } - $assign = $this->matchFuncGetArgsVariableAssign($node); - if (!$assign instanceof Assign) { + $expression = $this->matchFuncGetArgsVariableAssign($node); + if (!$expression instanceof Expression) { return \false; } + /** @var Assign $assign */ + $assign = $expression->expr; return $this->nodeComparator->areNodesEqual($assign->var, $variable); }); } /** + * @return Expression|null * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike */ - private function matchFuncGetArgsVariableAssign($functionLike) : ?Assign + private function matchFuncGetArgsVariableAssign($functionLike) : ?Expression { - /** @var Assign[] $assigns */ - $assigns = $this->betterNodeFinder->findInstancesOfInFunctionLikeScoped($functionLike, Assign::class); - foreach ($assigns as $assign) { + /** @var Expression[] $expressions */ + $expressions = $this->betterNodeFinder->findInstancesOfInFunctionLikeScoped($functionLike, Expression::class); + foreach ($expressions as $expression) { + if (!$expression->expr instanceof Assign) { + continue; + } + $assign = $expression->expr; if (!$assign->expr instanceof FuncCall) { continue; } if (!$this->isName($assign->expr, 'func_get_args')) { continue; } - return $assign; + return $expression; } return null; } diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 380cfa0643e..2fefde7382d 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = 'fa6f1f67578dbe765fc13abaa294e0f62e66d4a8'; + public const PACKAGE_VERSION = '11e6796c0044a9217aed0c725e4b0f7c5767cb22'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-05-24 13:23:20'; + public const RELEASE_DATE = '2023-05-24 13:03:26'; /** * @var int */ diff --git a/vendor/autoload.php b/vendor/autoload.php index 417c097c559..74d18b2454e 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) { require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInitca523d244187cbfb69b0f3557fae3ac2::getLoader(); +return ComposerAutoloaderInit7e485227a5b428fcc4384cec85ca4c67::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 394d210a38f..09618e71060 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInitca523d244187cbfb69b0f3557fae3ac2 +class ComposerAutoloaderInit7e485227a5b428fcc4384cec85ca4c67 { private static $loader; @@ -22,17 +22,17 @@ class ComposerAutoloaderInitca523d244187cbfb69b0f3557fae3ac2 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInitca523d244187cbfb69b0f3557fae3ac2', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit7e485227a5b428fcc4384cec85ca4c67', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); - spl_autoload_unregister(array('ComposerAutoloaderInitca523d244187cbfb69b0f3557fae3ac2', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit7e485227a5b428fcc4384cec85ca4c67', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInitca523d244187cbfb69b0f3557fae3ac2::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit7e485227a5b428fcc4384cec85ca4c67::getInitializer($loader)); $loader->setClassMapAuthoritative(true); $loader->register(true); - $filesToLoad = \Composer\Autoload\ComposerStaticInitca523d244187cbfb69b0f3557fae3ac2::$files; + $filesToLoad = \Composer\Autoload\ComposerStaticInit7e485227a5b428fcc4384cec85ca4c67::$files; $requireFile = \Closure::bind(static function ($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index cc6542aa650..17c8f4dd796 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInitca523d244187cbfb69b0f3557fae3ac2 +class ComposerStaticInit7e485227a5b428fcc4384cec85ca4c67 { public static $files = array ( 'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php', @@ -3105,9 +3105,9 @@ class ComposerStaticInitca523d244187cbfb69b0f3557fae3ac2 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInitca523d244187cbfb69b0f3557fae3ac2::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInitca523d244187cbfb69b0f3557fae3ac2::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInitca523d244187cbfb69b0f3557fae3ac2::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit7e485227a5b428fcc4384cec85ca4c67::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit7e485227a5b428fcc4384cec85ca4c67::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit7e485227a5b428fcc4384cec85ca4c67::$classMap; }, null, ClassLoader::class); }