From 1cfe2fe79372b27a994c50d9243848fb0849df8e Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Mon, 20 Dec 2021 18:22:21 +0000 Subject: [PATCH] Updated Rector to commit c51fcbf5ba8e4530c6992dafba25a447b89f24d0 https://github.com/rectorphp/rector-src/commit/c51fcbf5ba8e4530c6992dafba25a447b89f24d0 [Core] [DeadCode] Refactor RectifiedAnalyzer and ExprUsedInNextNodeAnalyzer (#1533) --- .../ExprUsedInNextNodeAnalyzer.php | 29 ++++--------------- src/Application/VersionResolver.php | 4 +-- src/ProcessAnalyzer/RectifiedAnalyzer.php | 15 +++++----- vendor/autoload.php | 2 +- vendor/composer/autoload_real.php | 14 ++++----- vendor/composer/autoload_static.php | 8 ++--- vendor/scoper-autoload.php | 10 +++---- 7 files changed, 33 insertions(+), 49 deletions(-) diff --git a/rules/DeadCode/NodeAnalyzer/ExprUsedInNextNodeAnalyzer.php b/rules/DeadCode/NodeAnalyzer/ExprUsedInNextNodeAnalyzer.php index ea63d439f12..7655acd544a 100644 --- a/rules/DeadCode/NodeAnalyzer/ExprUsedInNextNodeAnalyzer.php +++ b/rules/DeadCode/NodeAnalyzer/ExprUsedInNextNodeAnalyzer.php @@ -4,11 +4,8 @@ declare (strict_types=1); namespace Rector\DeadCode\NodeAnalyzer; use PhpParser\Node; -use PhpParser\Node\Arg; use PhpParser\Node\Expr; -use PhpParser\Node\Name; use PhpParser\Node\Stmt\If_; -use PHPStan\Analyser\Scope; use Rector\Core\PhpParser\Node\BetterNodeFinder; use Rector\EarlyReturn\Rector\If_\RemoveAlwaysElseRector; use Rector\NodeTypeResolver\Node\AttributeKey; @@ -29,31 +26,17 @@ final class ExprUsedInNextNodeAnalyzer $this->betterNodeFinder = $betterNodeFinder; $this->exprUsedInNodeAnalyzer = $exprUsedInNodeAnalyzer; } - /** - * $isCheckNameScope parameter is used to whether to check scope of Name that may be renamed - * @see https://github.com/rectorphp/rector/issues/6675 - */ - public function isUsed(\PhpParser\Node\Expr $expr, bool $isCheckNameScope = \false) : bool + public function isUsed(\PhpParser\Node\Expr $expr) : bool { - return (bool) $this->betterNodeFinder->findFirstNext($expr, function (\PhpParser\Node $node) use($expr, $isCheckNameScope) : bool { - if ($isCheckNameScope && $node instanceof \PhpParser\Node\Name) { - $scope = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::SCOPE); - $resolvedName = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::RESOLVED_NAME); - $next = $node->getAttribute(\Rector\NodeTypeResolver\Node\AttributeKey::NEXT_NODE); - if (!$scope instanceof \PHPStan\Analyser\Scope && !$resolvedName instanceof \PhpParser\Node\Name && $next instanceof \PhpParser\Node\Arg) { - return \true; - } - } - if (!$node instanceof \PhpParser\Node\Stmt\If_) { - return $this->exprUsedInNodeAnalyzer->isUsed($node, $expr); + return (bool) $this->betterNodeFinder->findFirstNext($expr, function (\PhpParser\Node $node) use($expr) : bool { + $isUsed = $this->exprUsedInNodeAnalyzer->isUsed($node, $expr); + if ($isUsed) { + return \true; } /** * handle when used along with RemoveAlwaysElseRector */ - if (!$this->hasIfChangedByRemoveAlwaysElseRector($node)) { - return $this->exprUsedInNodeAnalyzer->isUsed($node, $expr); - } - return \true; + return $node instanceof \PhpParser\Node\Stmt\If_ && $this->hasIfChangedByRemoveAlwaysElseRector($node); }); } private function hasIfChangedByRemoveAlwaysElseRector(\PhpParser\Node\Stmt\If_ $if) : bool diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 4c651703171..a905b59a7ed 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -16,11 +16,11 @@ final class VersionResolver /** * @var string */ - public const PACKAGE_VERSION = '2cdd339cda10577cfd45dfa18b1347780065e397'; + public const PACKAGE_VERSION = 'c51fcbf5ba8e4530c6992dafba25a447b89f24d0'; /** * @var string */ - public const RELEASE_DATE = '2021-12-20 19:02:31'; + public const RELEASE_DATE = '2021-12-20 19:02:58'; public static function resolvePackageVersion() : string { $process = new \RectorPrefix20211220\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__); diff --git a/src/ProcessAnalyzer/RectifiedAnalyzer.php b/src/ProcessAnalyzer/RectifiedAnalyzer.php index b2b1d211634..324e75b6096 100644 --- a/src/ProcessAnalyzer/RectifiedAnalyzer.php +++ b/src/ProcessAnalyzer/RectifiedAnalyzer.php @@ -4,8 +4,8 @@ declare (strict_types=1); namespace Rector\Core\ProcessAnalyzer; use PhpParser\Node; -use PhpParser\Node\Stmt; -use PhpParser\Node\Stmt\ClassLike; +use PhpParser\Node\Expr\Assign; +use PhpParser\Node\Stmt\Class_; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\Core\Contract\Rector\RectorInterface; use Rector\Core\ValueObject\Application\File; @@ -17,13 +17,17 @@ use Rector\Core\ValueObject\RectifiedNode; * * Some limitations: * - * - only check against Stmt which not ClassLike. + * - only check against Node which not Assign or Class_ * - The checked node doesn't has PhpDocInfo changed. * * which possibly changed by other process. */ final class RectifiedAnalyzer { + /** + * @var array> + */ + private const EXCLUDE_NODES = [\PhpParser\Node\Expr\Assign::class, \PhpParser\Node\Stmt\Class_::class]; /** * @var array */ @@ -39,10 +43,7 @@ final class RectifiedAnalyzer } public function verify(\Rector\Core\Contract\Rector\RectorInterface $rector, \PhpParser\Node $node, \Rector\Core\ValueObject\Application\File $currentFile) : ?\Rector\Core\ValueObject\RectifiedNode { - if (!$node instanceof \PhpParser\Node\Stmt) { - return null; - } - if ($node instanceof \PhpParser\Node\Stmt\ClassLike) { + if (\in_array(\get_class($node), self::EXCLUDE_NODES, \true)) { return null; } $phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node); diff --git a/vendor/autoload.php b/vendor/autoload.php index 4daec22e173..1cf5ab59595 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInitae22fc906da3cae5d930f1315a9c9596::getLoader(); +return ComposerAutoloaderInit1da546dbfe238e22804372367990b48b::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 72d51a202e3..34fff5180c8 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInitae22fc906da3cae5d930f1315a9c9596 +class ComposerAutoloaderInit1da546dbfe238e22804372367990b48b { private static $loader; @@ -22,15 +22,15 @@ class ComposerAutoloaderInitae22fc906da3cae5d930f1315a9c9596 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInitae22fc906da3cae5d930f1315a9c9596', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInit1da546dbfe238e22804372367990b48b', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__))); - spl_autoload_unregister(array('ComposerAutoloaderInitae22fc906da3cae5d930f1315a9c9596', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInit1da546dbfe238e22804372367990b48b', '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\ComposerStaticInitae22fc906da3cae5d930f1315a9c9596::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInit1da546dbfe238e22804372367990b48b::getInitializer($loader)); } else { $classMap = require __DIR__ . '/autoload_classmap.php'; if ($classMap) { @@ -42,19 +42,19 @@ class ComposerAutoloaderInitae22fc906da3cae5d930f1315a9c9596 $loader->register(true); if ($useStaticLoader) { - $includeFiles = Composer\Autoload\ComposerStaticInitae22fc906da3cae5d930f1315a9c9596::$files; + $includeFiles = Composer\Autoload\ComposerStaticInit1da546dbfe238e22804372367990b48b::$files; } else { $includeFiles = require __DIR__ . '/autoload_files.php'; } foreach ($includeFiles as $fileIdentifier => $file) { - composerRequireae22fc906da3cae5d930f1315a9c9596($fileIdentifier, $file); + composerRequire1da546dbfe238e22804372367990b48b($fileIdentifier, $file); } return $loader; } } -function composerRequireae22fc906da3cae5d930f1315a9c9596($fileIdentifier, $file) +function composerRequire1da546dbfe238e22804372367990b48b($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { require $file; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 9bee1acd647..17e0782ac5c 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInitae22fc906da3cae5d930f1315a9c9596 +class ComposerStaticInit1da546dbfe238e22804372367990b48b { public static $files = array ( '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php', @@ -3832,9 +3832,9 @@ class ComposerStaticInitae22fc906da3cae5d930f1315a9c9596 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInitae22fc906da3cae5d930f1315a9c9596::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInitae22fc906da3cae5d930f1315a9c9596::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInitae22fc906da3cae5d930f1315a9c9596::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInit1da546dbfe238e22804372367990b48b::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInit1da546dbfe238e22804372367990b48b::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInit1da546dbfe238e22804372367990b48b::$classMap; }, null, ClassLoader::class); } diff --git a/vendor/scoper-autoload.php b/vendor/scoper-autoload.php index 613e5a9c76d..db577a91154 100644 --- a/vendor/scoper-autoload.php +++ b/vendor/scoper-autoload.php @@ -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('RectorPrefix20211220\AutoloadIncluder'); } -if (!class_exists('ComposerAutoloaderInitae22fc906da3cae5d930f1315a9c9596', false) && !interface_exists('ComposerAutoloaderInitae22fc906da3cae5d930f1315a9c9596', false) && !trait_exists('ComposerAutoloaderInitae22fc906da3cae5d930f1315a9c9596', false)) { - spl_autoload_call('RectorPrefix20211220\ComposerAutoloaderInitae22fc906da3cae5d930f1315a9c9596'); +if (!class_exists('ComposerAutoloaderInit1da546dbfe238e22804372367990b48b', false) && !interface_exists('ComposerAutoloaderInit1da546dbfe238e22804372367990b48b', false) && !trait_exists('ComposerAutoloaderInit1da546dbfe238e22804372367990b48b', false)) { + spl_autoload_call('RectorPrefix20211220\ComposerAutoloaderInit1da546dbfe238e22804372367990b48b'); } 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('RectorPrefix20211220\Helmich\TypoScriptParser\Parser\AST\Statement'); @@ -78,9 +78,9 @@ if (!function_exists('print_node')) { return \RectorPrefix20211220\print_node(...func_get_args()); } } -if (!function_exists('composerRequireae22fc906da3cae5d930f1315a9c9596')) { - function composerRequireae22fc906da3cae5d930f1315a9c9596() { - return \RectorPrefix20211220\composerRequireae22fc906da3cae5d930f1315a9c9596(...func_get_args()); +if (!function_exists('composerRequire1da546dbfe238e22804372367990b48b')) { + function composerRequire1da546dbfe238e22804372367990b48b() { + return \RectorPrefix20211220\composerRequire1da546dbfe238e22804372367990b48b(...func_get_args()); } } if (!function_exists('scanPath')) {