Skip to content

Commit

Permalink
Updated Rector to commit c3e0ff3
Browse files Browse the repository at this point in the history
rectorphp/rector-src@c3e0ff3 [CodeQuality] Skip static variable on SimplifyUselessVariableRector (#630)
  • Loading branch information
TomasVotruba committed Aug 9, 2021
1 parent b2c929a commit 4cda207
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 21 deletions.
14 changes: 12 additions & 2 deletions rules/CodeQuality/Rector/Return_/SimplifyUselessVariableRector.php
Expand Up @@ -12,6 +12,7 @@
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;
Expand All @@ -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
{
Expand Down Expand Up @@ -105,6 +111,7 @@ private function shouldSkip(\PhpParser\Node\Stmt\Return_ $return) : bool
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) {
Expand All @@ -122,7 +129,10 @@ private function shouldSkip(\PhpParser\Node\Stmt\Return_ $return) : bool
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
{
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Expand Up @@ -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__);
Expand Down
40 changes: 40 additions & 0 deletions src/NodeAnalyzer/VariableAnalyzer.php
@@ -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 changes: 1 addition & 1 deletion vendor/autoload.php
Expand Up @@ -4,4 +4,4 @@

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit86dc8548a081f3138b10285749dfe7b2::getLoader();
return ComposerAutoloaderInit40d51fec79badfd9caf19394e4ab3634::getLoader();
1 change: 1 addition & 0 deletions vendor/composer/autoload_classmap.php
Expand Up @@ -1838,6 +1838,7 @@
'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',
Expand Down
14 changes: 7 additions & 7 deletions vendor/composer/autoload_real.php
Expand Up @@ -2,7 +2,7 @@

// autoload_real.php @generated by Composer

class ComposerAutoloaderInit86dc8548a081f3138b10285749dfe7b2
class ComposerAutoloaderInit40d51fec79badfd9caf19394e4ab3634
{
private static $loader;

Expand All @@ -22,15 +22,15 @@ public static function getLoader()
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) {
Expand All @@ -42,19 +42,19 @@ public static function getLoader()
$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;
Expand Down
9 changes: 5 additions & 4 deletions vendor/composer/autoload_static.php
Expand Up @@ -4,7 +4,7 @@

namespace Composer\Autoload;

class ComposerStaticInit86dc8548a081f3138b10285749dfe7b2
class ComposerStaticInit40d51fec79badfd9caf19394e4ab3634
{
public static $files = array (
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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);
}
Expand Down
10 changes: 5 additions & 5 deletions vendor/scoper-autoload.php
Expand Up @@ -9,8 +9,8 @@
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');
Expand Down Expand Up @@ -3305,9 +3305,9 @@ function 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')) {
Expand Down

0 comments on commit 4cda207

Please sign in to comment.