Updated Rector to commit c3e0ff311d85a62c22bd9220564e7283d74211bc

c3e0ff311d [CodeQuality] Skip static variable on SimplifyUselessVariableRector (#630)
This commit is contained in:
Tomas Votruba 2021-08-09 13:33:35 +00:00
parent b2c929a146
commit 4cda207f19
8 changed files with 73 additions and 21 deletions

View File

@ -12,6 +12,7 @@ use PhpParser\Node\FunctionLike;
use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Return_; use PhpParser\Node\Stmt\Return_;
use PHPStan\Type\MixedType; use PHPStan\Type\MixedType;
use Rector\Core\NodeAnalyzer\VariableAnalyzer;
use Rector\Core\PhpParser\Node\AssignAndBinaryMap; use Rector\Core\PhpParser\Node\AssignAndBinaryMap;
use Rector\Core\Rector\AbstractRector; use Rector\Core\Rector\AbstractRector;
use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\NodeTypeResolver\Node\AttributeKey;
@ -27,9 +28,14 @@ final class SimplifyUselessVariableRector extends \Rector\Core\Rector\AbstractRe
* @var \Rector\Core\PhpParser\Node\AssignAndBinaryMap * @var \Rector\Core\PhpParser\Node\AssignAndBinaryMap
*/ */
private $assignAndBinaryMap; private $assignAndBinaryMap;
public function __construct(\Rector\Core\PhpParser\Node\AssignAndBinaryMap $assignAndBinaryMap) /**
* @var \Rector\Core\NodeAnalyzer\VariableAnalyzer
*/
private $variableAnalyzer;
public function __construct(\Rector\Core\PhpParser\Node\AssignAndBinaryMap $assignAndBinaryMap, \Rector\Core\NodeAnalyzer\VariableAnalyzer $variableAnalyzer)
{ {
$this->assignAndBinaryMap = $assignAndBinaryMap; $this->assignAndBinaryMap = $assignAndBinaryMap;
$this->variableAnalyzer = $variableAnalyzer;
} }
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{ {
@ -105,6 +111,7 @@ CODE_SAMPLE
if ($this->hasByRefReturn($return)) { if ($this->hasByRefReturn($return)) {
return \true; return \true;
} }
/** @var Variable $variableNode */
$variableNode = $return->expr; $variableNode = $return->expr;
$previousExpression = $return->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PREVIOUS_NODE); $previousExpression = $return->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PREVIOUS_NODE);
if (!$previousExpression instanceof \PhpParser\Node) { if (!$previousExpression instanceof \PhpParser\Node) {
@ -122,7 +129,10 @@ CODE_SAMPLE
if (!$this->nodeComparator->areNodesEqual($previousNode->var, $variableNode)) { if (!$this->nodeComparator->areNodesEqual($previousNode->var, $variableNode)) {
return \true; return \true;
} }
return $this->isPreviousExpressionVisuallySimilar($previousExpression, $previousNode); if ($this->isPreviousExpressionVisuallySimilar($previousExpression, $previousNode)) {
return \true;
}
return $this->variableAnalyzer->isStatic($variableNode);
} }
private function hasSomeComment(\PhpParser\Node\Expr $expr) : bool private function hasSomeComment(\PhpParser\Node\Expr $expr) : bool
{ {

View File

@ -16,11 +16,11 @@ final class VersionResolver
/** /**
* @var string * @var string
*/ */
public const PACKAGE_VERSION = 'fa8e3bd295a21fa81f6a613c713dcf161897b0ae'; public const PACKAGE_VERSION = 'c3e0ff311d85a62c22bd9220564e7283d74211bc';
/** /**
* @var string * @var string
*/ */
public const RELEASE_DATE = '2021-08-09 11:49:05'; public const RELEASE_DATE = '2021-08-09 13:23:18';
public static function resolvePackageVersion() : string public static function resolvePackageVersion() : string
{ {
$process = new \RectorPrefix20210809\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__); $process = new \RectorPrefix20210809\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);

View File

@ -0,0 +1,40 @@
<?php
declare (strict_types=1);
namespace Rector\Core\NodeAnalyzer;
use PhpParser\Node;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Static_;
use Rector\Core\PhpParser\Comparing\NodeComparator;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
final class VariableAnalyzer
{
/**
* @var \Rector\Core\PhpParser\Node\BetterNodeFinder
*/
private $betterNodeFinder;
/**
* @var \Rector\Core\PhpParser\Comparing\NodeComparator
*/
private $nodeComparator;
public function __construct(\Rector\Core\PhpParser\Node\BetterNodeFinder $betterNodeFinder, \Rector\Core\PhpParser\Comparing\NodeComparator $nodeComparator)
{
$this->betterNodeFinder = $betterNodeFinder;
$this->nodeComparator = $nodeComparator;
}
public function isStatic(\PhpParser\Node\Expr\Variable $variable) : bool
{
return (bool) $this->betterNodeFinder->findFirstPreviousOfNode($variable, function (\PhpParser\Node $n) use($variable) : bool {
if (!$n instanceof \PhpParser\Node\Stmt\Static_) {
return \false;
}
foreach ($n->vars as $staticVar) {
if ($this->nodeComparator->areNodesEqual($staticVar->var, $variable)) {
return \true;
}
}
return \false;
});
}
}

2
vendor/autoload.php vendored
View File

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

View File

@ -1838,6 +1838,7 @@ return array(
'Rector\\Core\\NodeAnalyzer\\PromotedPropertyParamCleaner' => $baseDir . '/src/NodeAnalyzer/PromotedPropertyParamCleaner.php', 'Rector\\Core\\NodeAnalyzer\\PromotedPropertyParamCleaner' => $baseDir . '/src/NodeAnalyzer/PromotedPropertyParamCleaner.php',
'Rector\\Core\\NodeAnalyzer\\PropertyFetchAnalyzer' => $baseDir . '/src/NodeAnalyzer/PropertyFetchAnalyzer.php', 'Rector\\Core\\NodeAnalyzer\\PropertyFetchAnalyzer' => $baseDir . '/src/NodeAnalyzer/PropertyFetchAnalyzer.php',
'Rector\\Core\\NodeAnalyzer\\PropertyPresenceChecker' => $baseDir . '/src/NodeAnalyzer/PropertyPresenceChecker.php', 'Rector\\Core\\NodeAnalyzer\\PropertyPresenceChecker' => $baseDir . '/src/NodeAnalyzer/PropertyPresenceChecker.php',
'Rector\\Core\\NodeAnalyzer\\VariableAnalyzer' => $baseDir . '/src/NodeAnalyzer/VariableAnalyzer.php',
'Rector\\Core\\NodeAnalyzer\\VariadicAnalyzer' => $baseDir . '/src/NodeAnalyzer/VariadicAnalyzer.php', 'Rector\\Core\\NodeAnalyzer\\VariadicAnalyzer' => $baseDir . '/src/NodeAnalyzer/VariadicAnalyzer.php',
'Rector\\Core\\NodeFactory\\ClassWithPublicPropertiesFactory' => $baseDir . '/src/NodeFactory/ClassWithPublicPropertiesFactory.php', 'Rector\\Core\\NodeFactory\\ClassWithPublicPropertiesFactory' => $baseDir . '/src/NodeFactory/ClassWithPublicPropertiesFactory.php',
'Rector\\Core\\NodeManipulator\\ArrayDestructVariableFilter' => $baseDir . '/src/NodeManipulator/ArrayDestructVariableFilter.php', 'Rector\\Core\\NodeManipulator\\ArrayDestructVariableFilter' => $baseDir . '/src/NodeManipulator/ArrayDestructVariableFilter.php',

View File

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

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload; namespace Composer\Autoload;
class ComposerStaticInit86dc8548a081f3138b10285749dfe7b2 class ComposerStaticInit40d51fec79badfd9caf19394e4ab3634
{ {
public static $files = array ( public static $files = array (
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php', 'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
@ -2198,6 +2198,7 @@ class ComposerStaticInit86dc8548a081f3138b10285749dfe7b2
'Rector\\Core\\NodeAnalyzer\\PromotedPropertyParamCleaner' => __DIR__ . '/../..' . '/src/NodeAnalyzer/PromotedPropertyParamCleaner.php', 'Rector\\Core\\NodeAnalyzer\\PromotedPropertyParamCleaner' => __DIR__ . '/../..' . '/src/NodeAnalyzer/PromotedPropertyParamCleaner.php',
'Rector\\Core\\NodeAnalyzer\\PropertyFetchAnalyzer' => __DIR__ . '/../..' . '/src/NodeAnalyzer/PropertyFetchAnalyzer.php', 'Rector\\Core\\NodeAnalyzer\\PropertyFetchAnalyzer' => __DIR__ . '/../..' . '/src/NodeAnalyzer/PropertyFetchAnalyzer.php',
'Rector\\Core\\NodeAnalyzer\\PropertyPresenceChecker' => __DIR__ . '/../..' . '/src/NodeAnalyzer/PropertyPresenceChecker.php', 'Rector\\Core\\NodeAnalyzer\\PropertyPresenceChecker' => __DIR__ . '/../..' . '/src/NodeAnalyzer/PropertyPresenceChecker.php',
'Rector\\Core\\NodeAnalyzer\\VariableAnalyzer' => __DIR__ . '/../..' . '/src/NodeAnalyzer/VariableAnalyzer.php',
'Rector\\Core\\NodeAnalyzer\\VariadicAnalyzer' => __DIR__ . '/../..' . '/src/NodeAnalyzer/VariadicAnalyzer.php', 'Rector\\Core\\NodeAnalyzer\\VariadicAnalyzer' => __DIR__ . '/../..' . '/src/NodeAnalyzer/VariadicAnalyzer.php',
'Rector\\Core\\NodeFactory\\ClassWithPublicPropertiesFactory' => __DIR__ . '/../..' . '/src/NodeFactory/ClassWithPublicPropertiesFactory.php', 'Rector\\Core\\NodeFactory\\ClassWithPublicPropertiesFactory' => __DIR__ . '/../..' . '/src/NodeFactory/ClassWithPublicPropertiesFactory.php',
'Rector\\Core\\NodeManipulator\\ArrayDestructVariableFilter' => __DIR__ . '/../..' . '/src/NodeManipulator/ArrayDestructVariableFilter.php', 'Rector\\Core\\NodeManipulator\\ArrayDestructVariableFilter' => __DIR__ . '/../..' . '/src/NodeManipulator/ArrayDestructVariableFilter.php',
@ -3848,9 +3849,9 @@ class ComposerStaticInit86dc8548a081f3138b10285749dfe7b2
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 = ComposerStaticInit86dc8548a081f3138b10285749dfe7b2::$prefixLengthsPsr4; $loader->prefixLengthsPsr4 = ComposerStaticInit40d51fec79badfd9caf19394e4ab3634::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit86dc8548a081f3138b10285749dfe7b2::$prefixDirsPsr4; $loader->prefixDirsPsr4 = ComposerStaticInit40d51fec79badfd9caf19394e4ab3634::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit86dc8548a081f3138b10285749dfe7b2::$classMap; $loader->classMap = ComposerStaticInit40d51fec79badfd9caf19394e4ab3634::$classMap;
}, null, ClassLoader::class); }, 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)) { if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
spl_autoload_call('RectorPrefix20210809\AutoloadIncluder'); spl_autoload_call('RectorPrefix20210809\AutoloadIncluder');
} }
if (!class_exists('ComposerAutoloaderInit86dc8548a081f3138b10285749dfe7b2', false) && !interface_exists('ComposerAutoloaderInit86dc8548a081f3138b10285749dfe7b2', false) && !trait_exists('ComposerAutoloaderInit86dc8548a081f3138b10285749dfe7b2', false)) { if (!class_exists('ComposerAutoloaderInit40d51fec79badfd9caf19394e4ab3634', false) && !interface_exists('ComposerAutoloaderInit40d51fec79badfd9caf19394e4ab3634', false) && !trait_exists('ComposerAutoloaderInit40d51fec79badfd9caf19394e4ab3634', false)) {
spl_autoload_call('RectorPrefix20210809\ComposerAutoloaderInit86dc8548a081f3138b10285749dfe7b2'); spl_autoload_call('RectorPrefix20210809\ComposerAutoloaderInit40d51fec79badfd9caf19394e4ab3634');
} }
if (!class_exists('AjaxLogin', false) && !interface_exists('AjaxLogin', false) && !trait_exists('AjaxLogin', false)) { if (!class_exists('AjaxLogin', false) && !interface_exists('AjaxLogin', false) && !trait_exists('AjaxLogin', false)) {
spl_autoload_call('RectorPrefix20210809\AjaxLogin'); spl_autoload_call('RectorPrefix20210809\AjaxLogin');
@ -3305,9 +3305,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20210809\print_node(...func_get_args()); return \RectorPrefix20210809\print_node(...func_get_args());
} }
} }
if (!function_exists('composerRequire86dc8548a081f3138b10285749dfe7b2')) { if (!function_exists('composerRequire40d51fec79badfd9caf19394e4ab3634')) {
function composerRequire86dc8548a081f3138b10285749dfe7b2() { function composerRequire40d51fec79badfd9caf19394e4ab3634() {
return \RectorPrefix20210809\composerRequire86dc8548a081f3138b10285749dfe7b2(...func_get_args()); return \RectorPrefix20210809\composerRequire40d51fec79badfd9caf19394e4ab3634(...func_get_args());
} }
} }
if (!function_exists('parseArgs')) { if (!function_exists('parseArgs')) {