Updated Rector to commit 11e6796c0044a9217aed0c725e4b0f7c5767cb22

11e6796c00 Remove PARENT_NODE from FuncGetArgsToVariadicParamRector (#3949)
This commit is contained in:
Tomas Votruba 2023-05-24 13:08:24 +00:00
parent 26ac08e306
commit bddc5333e6
5 changed files with 34 additions and 57 deletions

View File

@ -4,21 +4,16 @@ declare (strict_types=1);
namespace Rector\CodingStyle\Rector\ClassMethod; namespace Rector\CodingStyle\Rector\ClassMethod;
use PhpParser\Node; use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Variable; use PhpParser\Node\Expr\Variable;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Param; use PhpParser\Node\Param;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Function_; use PhpParser\Node\Stmt\Function_;
use Rector\Core\Rector\AbstractRector; use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature; use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@ -59,20 +54,23 @@ CODE_SAMPLE
if ($node->params !== []) { if ($node->params !== []) {
return null; return null;
} }
$assign = $this->matchFuncGetArgsVariableAssign($node); /** @var Expression<Assign>|null $expression */
if (!$assign instanceof Assign) { $expression = $this->matchFuncGetArgsVariableAssign($node);
if (!$expression instanceof Expression) {
return null; return null;
} }
/** @var Assign $assign */
$assign = $expression->expr;
if ($assign->var instanceof Variable) { if ($assign->var instanceof Variable) {
$variableName = $this->getName($assign->var); $variableName = $this->getName($assign->var);
if ($variableName === null) { if ($variableName === null) {
return null; return null;
} }
return $this->removeOrChangeAssignToVariable($node, $assign, $variableName); $this->removeNode($assign);
return $this->applyVariadicParams($node, $variableName);
} }
$variableName = 'args';
$assign->expr = new Variable('args'); $assign->expr = new Variable('args');
return $this->applyVariadicParams($node, $variableName); return $this->applyVariadicParams($node, 'args');
} }
public function provideMinPhpVersion() : int public function provideMinPhpVersion() : int
{ {
@ -92,34 +90,6 @@ CODE_SAMPLE
$node->params[] = $param; $node->params[] = $param;
return $node; 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 * @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike
*/ */
@ -135,28 +105,35 @@ CODE_SAMPLE
if ($node->params !== []) { if ($node->params !== []) {
return \false; return \false;
} }
$assign = $this->matchFuncGetArgsVariableAssign($node); $expression = $this->matchFuncGetArgsVariableAssign($node);
if (!$assign instanceof Assign) { if (!$expression instanceof Expression) {
return \false; return \false;
} }
/** @var Assign $assign */
$assign = $expression->expr;
return $this->nodeComparator->areNodesEqual($assign->var, $variable); return $this->nodeComparator->areNodesEqual($assign->var, $variable);
}); });
} }
/** /**
* @return Expression<Assign>|null
* @param \PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $functionLike * @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 */ /** @var Expression[] $expressions */
$assigns = $this->betterNodeFinder->findInstancesOfInFunctionLikeScoped($functionLike, Assign::class); $expressions = $this->betterNodeFinder->findInstancesOfInFunctionLikeScoped($functionLike, Expression::class);
foreach ($assigns as $assign) { foreach ($expressions as $expression) {
if (!$expression->expr instanceof Assign) {
continue;
}
$assign = $expression->expr;
if (!$assign->expr instanceof FuncCall) { if (!$assign->expr instanceof FuncCall) {
continue; continue;
} }
if (!$this->isName($assign->expr, 'func_get_args')) { if (!$this->isName($assign->expr, 'func_get_args')) {
continue; continue;
} }
return $assign; return $expression;
} }
return null; return null;
} }

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api * @api
* @var string * @var string
*/ */
public const PACKAGE_VERSION = 'fa6f1f67578dbe765fc13abaa294e0f62e66d4a8'; public const PACKAGE_VERSION = '11e6796c0044a9217aed0c725e4b0f7c5767cb22';
/** /**
* @api * @api
* @var string * @var string
*/ */
public const RELEASE_DATE = '2023-05-24 13:23:20'; public const RELEASE_DATE = '2023-05-24 13:03:26';
/** /**
* @var int * @var int
*/ */

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php'; require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitca523d244187cbfb69b0f3557fae3ac2::getLoader(); return ComposerAutoloaderInit7e485227a5b428fcc4384cec85ca4c67::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer // autoload_real.php @generated by Composer
class ComposerAutoloaderInitca523d244187cbfb69b0f3557fae3ac2 class ComposerAutoloaderInit7e485227a5b428fcc4384cec85ca4c67
{ {
private static $loader; private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInitca523d244187cbfb69b0f3557fae3ac2
return self::$loader; 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__)); 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'; 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->setClassMapAuthoritative(true);
$loader->register(true); $loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInitca523d244187cbfb69b0f3557fae3ac2::$files; $filesToLoad = \Composer\Autoload\ComposerStaticInit7e485227a5b428fcc4384cec85ca4c67::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) { $requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload; namespace Composer\Autoload;
class ComposerStaticInitca523d244187cbfb69b0f3557fae3ac2 class ComposerStaticInit7e485227a5b428fcc4384cec85ca4c67
{ {
public static $files = array ( public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php', 'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3105,9 +3105,9 @@ class ComposerStaticInitca523d244187cbfb69b0f3557fae3ac2
public static function getInitializer(ClassLoader $loader) public static function getInitializer(ClassLoader $loader)
{ {
return \Closure::bind(function () use ($loader) { return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitca523d244187cbfb69b0f3557fae3ac2::$prefixLengthsPsr4; $loader->prefixLengthsPsr4 = ComposerStaticInit7e485227a5b428fcc4384cec85ca4c67::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitca523d244187cbfb69b0f3557fae3ac2::$prefixDirsPsr4; $loader->prefixDirsPsr4 = ComposerStaticInit7e485227a5b428fcc4384cec85ca4c67::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitca523d244187cbfb69b0f3557fae3ac2::$classMap; $loader->classMap = ComposerStaticInit7e485227a5b428fcc4384cec85ca4c67::$classMap;
}, null, ClassLoader::class); }, null, ClassLoader::class);
} }