mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-19 14:27:14 +01:00
Updated Rector to commit c3e0ff311d85a62c22bd9220564e7283d74211bc
c3e0ff311d
[CodeQuality] Skip static variable on SimplifyUselessVariableRector (#630)
This commit is contained in:
parent
b2c929a146
commit
4cda207f19
@ -12,6 +12,7 @@ use PhpParser\Node\FunctionLike;
|
||||
use PhpParser\Node\Stmt\Expression;
|
||||
use PhpParser\Node\Stmt\Return_;
|
||||
use PHPStan\Type\MixedType;
|
||||
use Rector\Core\NodeAnalyzer\VariableAnalyzer;
|
||||
use Rector\Core\PhpParser\Node\AssignAndBinaryMap;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
@ -27,9 +28,14 @@ final class SimplifyUselessVariableRector extends \Rector\Core\Rector\AbstractRe
|
||||
* @var \Rector\Core\PhpParser\Node\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->variableAnalyzer = $variableAnalyzer;
|
||||
}
|
||||
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
|
||||
{
|
||||
@ -105,6 +111,7 @@ CODE_SAMPLE
|
||||
if ($this->hasByRefReturn($return)) {
|
||||
return \true;
|
||||
}
|
||||
/** @var Variable $variableNode */
|
||||
$variableNode = $return->expr;
|
||||
$previousExpression = $return->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::PREVIOUS_NODE);
|
||||
if (!$previousExpression instanceof \PhpParser\Node) {
|
||||
@ -122,7 +129,10 @@ CODE_SAMPLE
|
||||
if (!$this->nodeComparator->areNodesEqual($previousNode->var, $variableNode)) {
|
||||
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
|
||||
{
|
||||
|
@ -16,11 +16,11 @@ final class VersionResolver
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'fa8e3bd295a21fa81f6a613c713dcf161897b0ae';
|
||||
public const PACKAGE_VERSION = 'c3e0ff311d85a62c22bd9220564e7283d74211bc';
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
$process = new \RectorPrefix20210809\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);
|
||||
|
40
src/NodeAnalyzer/VariableAnalyzer.php
Normal file
40
src/NodeAnalyzer/VariableAnalyzer.php
Normal 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
2
vendor/autoload.php
vendored
@ -4,4 +4,4 @@
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit86dc8548a081f3138b10285749dfe7b2::getLoader();
|
||||
return ComposerAutoloaderInit40d51fec79badfd9caf19394e4ab3634::getLoader();
|
||||
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
@ -1838,6 +1838,7 @@ return array(
|
||||
'Rector\\Core\\NodeAnalyzer\\PromotedPropertyParamCleaner' => $baseDir . '/src/NodeAnalyzer/PromotedPropertyParamCleaner.php',
|
||||
'Rector\\Core\\NodeAnalyzer\\PropertyFetchAnalyzer' => $baseDir . '/src/NodeAnalyzer/PropertyFetchAnalyzer.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\\NodeFactory\\ClassWithPublicPropertiesFactory' => $baseDir . '/src/NodeFactory/ClassWithPublicPropertiesFactory.php',
|
||||
'Rector\\Core\\NodeManipulator\\ArrayDestructVariableFilter' => $baseDir . '/src/NodeManipulator/ArrayDestructVariableFilter.php',
|
||||
|
14
vendor/composer/autoload_real.php
vendored
14
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit86dc8548a081f3138b10285749dfe7b2
|
||||
class ComposerAutoloaderInit40d51fec79badfd9caf19394e4ab3634
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,15 +22,15 @@ class ComposerAutoloaderInit86dc8548a081f3138b10285749dfe7b2
|
||||
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__)));
|
||||
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());
|
||||
if ($useStaticLoader) {
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit86dc8548a081f3138b10285749dfe7b2::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit40d51fec79badfd9caf19394e4ab3634::getInitializer($loader));
|
||||
} else {
|
||||
$classMap = require __DIR__ . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
@ -42,19 +42,19 @@ class ComposerAutoloaderInit86dc8548a081f3138b10285749dfe7b2
|
||||
$loader->register(true);
|
||||
|
||||
if ($useStaticLoader) {
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit86dc8548a081f3138b10285749dfe7b2::$files;
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit40d51fec79badfd9caf19394e4ab3634::$files;
|
||||
} else {
|
||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||
}
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire86dc8548a081f3138b10285749dfe7b2($fileIdentifier, $file);
|
||||
composerRequire40d51fec79badfd9caf19394e4ab3634($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
||||
|
||||
function composerRequire86dc8548a081f3138b10285749dfe7b2($fileIdentifier, $file)
|
||||
function composerRequire40d51fec79badfd9caf19394e4ab3634($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
require $file;
|
||||
|
9
vendor/composer/autoload_static.php
vendored
9
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit86dc8548a081f3138b10285749dfe7b2
|
||||
class ComposerStaticInit40d51fec79badfd9caf19394e4ab3634
|
||||
{
|
||||
public static $files = array (
|
||||
'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\\PropertyFetchAnalyzer' => __DIR__ . '/../..' . '/src/NodeAnalyzer/PropertyFetchAnalyzer.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\\NodeFactory\\ClassWithPublicPropertiesFactory' => __DIR__ . '/../..' . '/src/NodeFactory/ClassWithPublicPropertiesFactory.php',
|
||||
'Rector\\Core\\NodeManipulator\\ArrayDestructVariableFilter' => __DIR__ . '/../..' . '/src/NodeManipulator/ArrayDestructVariableFilter.php',
|
||||
@ -3848,9 +3849,9 @@ class ComposerStaticInit86dc8548a081f3138b10285749dfe7b2
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit86dc8548a081f3138b10285749dfe7b2::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit86dc8548a081f3138b10285749dfe7b2::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit86dc8548a081f3138b10285749dfe7b2::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit40d51fec79badfd9caf19394e4ab3634::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit40d51fec79badfd9caf19394e4ab3634::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit40d51fec79badfd9caf19394e4ab3634::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
10
vendor/scoper-autoload.php
vendored
10
vendor/scoper-autoload.php
vendored
@ -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('RectorPrefix20210809\AutoloadIncluder');
|
||||
}
|
||||
if (!class_exists('ComposerAutoloaderInit86dc8548a081f3138b10285749dfe7b2', false) && !interface_exists('ComposerAutoloaderInit86dc8548a081f3138b10285749dfe7b2', false) && !trait_exists('ComposerAutoloaderInit86dc8548a081f3138b10285749dfe7b2', false)) {
|
||||
spl_autoload_call('RectorPrefix20210809\ComposerAutoloaderInit86dc8548a081f3138b10285749dfe7b2');
|
||||
if (!class_exists('ComposerAutoloaderInit40d51fec79badfd9caf19394e4ab3634', false) && !interface_exists('ComposerAutoloaderInit40d51fec79badfd9caf19394e4ab3634', false) && !trait_exists('ComposerAutoloaderInit40d51fec79badfd9caf19394e4ab3634', false)) {
|
||||
spl_autoload_call('RectorPrefix20210809\ComposerAutoloaderInit40d51fec79badfd9caf19394e4ab3634');
|
||||
}
|
||||
if (!class_exists('AjaxLogin', false) && !interface_exists('AjaxLogin', false) && !trait_exists('AjaxLogin', false)) {
|
||||
spl_autoload_call('RectorPrefix20210809\AjaxLogin');
|
||||
@ -3305,9 +3305,9 @@ if (!function_exists('print_node')) {
|
||||
return \RectorPrefix20210809\print_node(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('composerRequire86dc8548a081f3138b10285749dfe7b2')) {
|
||||
function composerRequire86dc8548a081f3138b10285749dfe7b2() {
|
||||
return \RectorPrefix20210809\composerRequire86dc8548a081f3138b10285749dfe7b2(...func_get_args());
|
||||
if (!function_exists('composerRequire40d51fec79badfd9caf19394e4ab3634')) {
|
||||
function composerRequire40d51fec79badfd9caf19394e4ab3634() {
|
||||
return \RectorPrefix20210809\composerRequire40d51fec79badfd9caf19394e4ab3634(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('parseArgs')) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user