Updated Rector to commit 31cffa807a

31cffa807a [Php56] Clean up AddDefaultValueForUndefinedVariableRector: remove unnecessary repetitive apply and used from params (#1778)
This commit is contained in:
Tomas Votruba 2022-02-08 10:54:04 +00:00
parent 38cea3ebb0
commit 63321bd3f6
7 changed files with 20 additions and 46 deletions

View File

@ -66,8 +66,7 @@ final class UndefinedVariableResolver
public function resolve($node) : array
{
$undefinedVariables = [];
$variableNamesFromParams = $this->collectVariableNamesFromParams($node);
$this->simpleCallableNodeTraverser->traverseNodesWithCallable((array) $node->stmts, function (\PhpParser\Node $node) use(&$undefinedVariables, $variableNamesFromParams) : ?int {
$this->simpleCallableNodeTraverser->traverseNodesWithCallable((array) $node->stmts, function (\PhpParser\Node $node) use(&$undefinedVariables) : ?int {
// entering new scope - break!
if ($node instanceof \PhpParser\Node\FunctionLike && !$node instanceof \PhpParser\Node\Expr\ArrowFunction) {
return \PhpParser\NodeTraverser::STOP_TRAVERSAL;
@ -92,28 +91,11 @@ final class UndefinedVariableResolver
if ($scope->hasVariableType($variableName)->yes()) {
return null;
}
if (\in_array($variableName, $variableNamesFromParams, \true)) {
return null;
}
$undefinedVariables[] = $variableName;
return null;
});
return \array_unique($undefinedVariables);
}
/**
* @return string[]
* @param \PhpParser\Node\Expr\Closure|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_ $node
*/
private function collectVariableNamesFromParams($node) : array
{
$variableNames = [];
foreach ($node->getParams() as $param) {
if ($param->var instanceof \PhpParser\Node\Expr\Variable) {
$variableNames[] = (string) $this->nodeNameResolver->getName($param->var);
}
}
return $variableNames;
}
private function issetOrUnsetOrEmptyParent(\PhpParser\Node $parentNode) : bool
{
return \in_array(\get_class($parentNode), [\PhpParser\Node\Stmt\Unset_::class, \PhpParser\Node\Expr\Cast\Unset_::class, \PhpParser\Node\Expr\Isset_::class, \PhpParser\Node\Expr\Empty_::class], \true);

View File

@ -28,10 +28,6 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
*/
final class AddDefaultValueForUndefinedVariableRector extends \Rector\Core\Rector\AbstractRector implements \Rector\VersionBonding\Contract\MinPhpVersionInterface
{
/**
* @var string
*/
private const ALREADY_ADDED_VARIABLE_NAMES = 'already_added_variable_names';
/**
* @readonly
* @var \Rector\Php56\NodeAnalyzer\UndefinedVariableResolver
@ -96,9 +92,6 @@ CODE_SAMPLE
return null;
}
$undefinedVariableNames = $this->undefinedVariableResolver->resolve($node);
// avoids adding same variable multiple tiemes
$alreadyAddedVariableNames = (array) $node->getAttribute(self::ALREADY_ADDED_VARIABLE_NAMES);
$undefinedVariableNames = \array_diff($undefinedVariableNames, $alreadyAddedVariableNames);
if ($undefinedVariableNames === []) {
return null;
}
@ -108,7 +101,6 @@ CODE_SAMPLE
$assign = new \PhpParser\Node\Expr\Assign(new \PhpParser\Node\Expr\Variable($undefinedVariableName), $value);
$variablesInitiation[] = new \PhpParser\Node\Stmt\Expression($assign);
}
$node->setAttribute(self::ALREADY_ADDED_VARIABLE_NAMES, $undefinedVariableNames);
$node->stmts = \array_merge($variablesInitiation, (array) $node->stmts);
return $node;
}

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = '43c67255dd80431d2d1f9ab62dd1df728a86da17';
public const PACKAGE_VERSION = '31cffa807a44773ae7e415477150f051c2e66456';
/**
* @var string
*/
public const RELEASE_DATE = '2022-02-08 10:36:12';
public const RELEASE_DATE = '2022-02-08 11:47:42';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20220208\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit2107357f543250c2d9b43938ab54eb09::getLoader();
return ComposerAutoloaderInitb2b6fd0a5276d6f47ab9e6faa77644d9::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit2107357f543250c2d9b43938ab54eb09
class ComposerAutoloaderInitb2b6fd0a5276d6f47ab9e6faa77644d9
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInit2107357f543250c2d9b43938ab54eb09
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit2107357f543250c2d9b43938ab54eb09', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitb2b6fd0a5276d6f47ab9e6faa77644d9', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInit2107357f543250c2d9b43938ab54eb09', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitb2b6fd0a5276d6f47ab9e6faa77644d9', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit2107357f543250c2d9b43938ab54eb09::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitb2b6fd0a5276d6f47ab9e6faa77644d9::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,12 +42,12 @@ class ComposerAutoloaderInit2107357f543250c2d9b43938ab54eb09
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit2107357f543250c2d9b43938ab54eb09::$files;
$includeFiles = Composer\Autoload\ComposerStaticInitb2b6fd0a5276d6f47ab9e6faa77644d9::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire2107357f543250c2d9b43938ab54eb09($fileIdentifier, $file);
composerRequireb2b6fd0a5276d6f47ab9e6faa77644d9($fileIdentifier, $file);
}
return $loader;
@ -59,7 +59,7 @@ class ComposerAutoloaderInit2107357f543250c2d9b43938ab54eb09
* @param string $file
* @return void
*/
function composerRequire2107357f543250c2d9b43938ab54eb09($fileIdentifier, $file)
function composerRequireb2b6fd0a5276d6f47ab9e6faa77644d9($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit2107357f543250c2d9b43938ab54eb09
class ComposerStaticInitb2b6fd0a5276d6f47ab9e6faa77644d9
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
@ -3862,9 +3862,9 @@ class ComposerStaticInit2107357f543250c2d9b43938ab54eb09
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit2107357f543250c2d9b43938ab54eb09::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit2107357f543250c2d9b43938ab54eb09::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit2107357f543250c2d9b43938ab54eb09::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitb2b6fd0a5276d6f47ab9e6faa77644d9::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitb2b6fd0a5276d6f47ab9e6faa77644d9::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitb2b6fd0a5276d6f47ab9e6faa77644d9::$classMap;
}, null, ClassLoader::class);
}

View File

@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
spl_autoload_call('RectorPrefix20220208\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInit2107357f543250c2d9b43938ab54eb09', false) && !interface_exists('ComposerAutoloaderInit2107357f543250c2d9b43938ab54eb09', false) && !trait_exists('ComposerAutoloaderInit2107357f543250c2d9b43938ab54eb09', false)) {
spl_autoload_call('RectorPrefix20220208\ComposerAutoloaderInit2107357f543250c2d9b43938ab54eb09');
if (!class_exists('ComposerAutoloaderInitb2b6fd0a5276d6f47ab9e6faa77644d9', false) && !interface_exists('ComposerAutoloaderInitb2b6fd0a5276d6f47ab9e6faa77644d9', false) && !trait_exists('ComposerAutoloaderInitb2b6fd0a5276d6f47ab9e6faa77644d9', false)) {
spl_autoload_call('RectorPrefix20220208\ComposerAutoloaderInitb2b6fd0a5276d6f47ab9e6faa77644d9');
}
if (!class_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !interface_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false) && !trait_exists('Helmich\TypoScriptParser\Parser\AST\Statement', false)) {
spl_autoload_call('RectorPrefix20220208\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -71,9 +71,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20220208\print_node(...func_get_args());
}
}
if (!function_exists('composerRequire2107357f543250c2d9b43938ab54eb09')) {
function composerRequire2107357f543250c2d9b43938ab54eb09() {
return \RectorPrefix20220208\composerRequire2107357f543250c2d9b43938ab54eb09(...func_get_args());
if (!function_exists('composerRequireb2b6fd0a5276d6f47ab9e6faa77644d9')) {
function composerRequireb2b6fd0a5276d6f47ab9e6faa77644d9() {
return \RectorPrefix20220208\composerRequireb2b6fd0a5276d6f47ab9e6faa77644d9(...func_get_args());
}
}
if (!function_exists('scanPath')) {