mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 21:38:22 +01:00
Updated Rector to commit c51fcbf5ba8e4530c6992dafba25a447b89f24d0
c51fcbf5ba
[Core] [DeadCode] Refactor RectifiedAnalyzer and ExprUsedInNextNodeAnalyzer (#1533)
This commit is contained in:
parent
f5b0302b93
commit
1cfe2fe793
@ -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
|
||||
|
@ -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__);
|
||||
|
@ -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<class-string<Node>>
|
||||
*/
|
||||
private const EXCLUDE_NODES = [\PhpParser\Node\Expr\Assign::class, \PhpParser\Node\Stmt\Class_::class];
|
||||
/**
|
||||
* @var array<string, RectifiedNode|null>
|
||||
*/
|
||||
@ -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);
|
||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -4,4 +4,4 @@
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInitae22fc906da3cae5d930f1315a9c9596::getLoader();
|
||||
return ComposerAutoloaderInit1da546dbfe238e22804372367990b48b::getLoader();
|
||||
|
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 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;
|
||||
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
@ -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);
|
||||
}
|
||||
|
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('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')) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user