Updated Rector to commit 143f743d4ffb63b8fa6649841782d6d48735d472

143f743d4f [DX] Add MissingInSetCommand, to verify what rules are not part of their sets (#2594)
This commit is contained in:
Tomas Votruba 2022-06-30 13:31:25 +00:00
parent ff3ea12e20
commit 26c0e5c79b
8 changed files with 44 additions and 24 deletions

View File

@ -37,6 +37,7 @@ use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocator\Intermedia
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider;
use Rector\PSR4\Composer\PSR4NamespaceMatcher;
use Rector\PSR4\Contract\PSR4AutoloadNamespaceMatcherInterface;
use Rector\Utils\Command\MissingInSetCommand;
use RectorPrefix202206\Symfony\Component\Console\Application;
use function RectorPrefix202206\Symfony\Component\DependencyInjection\Loader\Configurator\service;
use RectorPrefix202206\Symplify\Astral\NodeTraverser\SimpleCallableNodeTraverser;
@ -138,4 +139,5 @@ return static function (RectorConfig $rectorConfig) : void {
$services->set(ScopeFactory::class)->factory([service(PHPStanServicesFactory::class), 'createScopeFactory']);
$services->set(TypeNodeResolver::class)->factory([service(PHPStanServicesFactory::class), 'createTypeNodeResolver']);
$services->set(DynamicSourceLocatorProvider::class)->factory([service(PHPStanServicesFactory::class), 'createDynamicSourceLocatorProvider']);
$services->set(MissingInSetCommand::class);
};

View File

@ -55,8 +55,8 @@ final class ExprParameterReflectionTypeCorrector
if (!$attributeClassReflection->hasConstructor()) {
return $items;
}
$constructorClassMethodReflection = $attributeClassReflection->getConstructor();
$parametersAcceptor = ParametersAcceptorSelector::selectSingle($constructorClassMethodReflection->getVariants());
$extendedMethodReflection = $attributeClassReflection->getConstructor();
$parametersAcceptor = ParametersAcceptorSelector::selectSingle($extendedMethodReflection->getVariants());
foreach ($items as $name => $item) {
foreach ($parametersAcceptor->getParameters() as $parameterReflection) {
$correctedItem = $this->correctItemByParameterReflection($name, $item, $parameterReflection);

View File

@ -6,6 +6,8 @@ namespace Rector\DeadCode\Rector\StmtsAwareInterface;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\ClosureUse;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\Variable;
@ -93,9 +95,12 @@ CODE_SAMPLE
continue;
}
$followingStmts = \array_slice($stmts, $key + 1);
if ($this->isFollowingStatementStaticClosure($followingStmts)) {
// can not replace usages in anonymous static functions
continue;
}
$variableUsages = $this->nodeUsageFinder->findVariableUsages($followingStmts, $variableToPropertyAssign->getVariable());
$currentStmtKey = $key;
// @todo validate the variable is not used in some place where property fetch cannot be used
break;
}
// filter out variable usages that are part of nested property fetch, or change variable
@ -109,6 +114,13 @@ CODE_SAMPLE
/** @var int $currentStmtKey */
return $this->replaceVariablesWithPropertyFetch($node, $currentStmtKey, $variableUsages, $variableToPropertyAssign->getPropertyFetch());
}
/**
* @param Stmt[] $followingStmts
*/
public function isFollowingStatementStaticClosure(array $followingStmts) : bool
{
return \count($followingStmts) > 0 && $followingStmts[0] instanceof Expression && $followingStmts[0]->expr instanceof Closure && $followingStmts[0]->expr->static;
}
/**
* @param Variable[] $variableUsages
*/
@ -116,10 +128,16 @@ CODE_SAMPLE
{
// remove assign node
unset($stmtsAware->stmts[$currentStmtsKey]);
$this->traverseNodesWithCallable($stmtsAware, static function (Node $node) use($variableUsages, $propertyFetch) : ?PropertyFetch {
$this->traverseNodesWithCallable($stmtsAware, function (Node $node) use($variableUsages, $propertyFetch) : ?PropertyFetch {
if (!\in_array($node, $variableUsages, \true)) {
return null;
}
$parentNode = $node->getAttribute(AttributeKey::PARENT_NODE);
if ($parentNode instanceof ClosureUse) {
// remove closure use which will be replaced by a property fetch
$this->nodesToRemoveCollector->addNodeToRemove($parentNode);
return null;
}
return $propertyFetch;
});
return $stmtsAware;

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = '09df9d00bd01094d8e5921a2aadd9f6298f333be';
public const PACKAGE_VERSION = '143f743d4ffb63b8fa6649841782d6d48735d472';
/**
* @var string
*/
public const RELEASE_DATE = '2022-06-30 14:41:13';
public const RELEASE_DATE = '2022-06-30 15:26:19';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

@ -9,4 +9,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitddf510289ef549bb5ae140bb78df7cba::getLoader();
return ComposerAutoloaderInitfca18ff1edd9fce0f35bc4b9397ad687::getLoader();

View File

@ -9,6 +9,7 @@ return array(
'Symplify\\RuleDocGenerator\\' => array($vendorDir . '/symplify/rule-doc-generator-contracts/src'),
'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'),
'Symfony\\Polyfill\\Intl\\Normalizer\\' => array($vendorDir . '/symfony/polyfill-intl-normalizer'),
'Rector\\Utils\\' => array($baseDir . '/utils'),
'Rector\\Symfony\\' => array($vendorDir . '/rector/rector-symfony/src'),
'Rector\\Set\\' => array($vendorDir . '/rector/rector-downgrade-php/packages/Set'),
'Rector\\RectorInstaller\\' => array($vendorDir . '/rector/extension-installer/src'),
@ -19,7 +20,6 @@ return array(
'Rector\\Laravel\\' => array($vendorDir . '/rector/rector-laravel/src'),
'Rector\\Doctrine\\' => array($vendorDir . '/rector/rector-doctrine/src'),
'Rector\\Core\\' => array($baseDir . '/src'),
'Rector\\Compiler\\' => array($baseDir . '/utils/compiler/src'),
'Rector\\CakePHP\\' => array($vendorDir . '/rector/rector-cakephp/src'),
'Rector\\' => array($baseDir . '/packages', $baseDir . '/rules', $vendorDir . '/rector/rector-downgrade-php/src'),
'RectorPrefix202206\\Webmozart\\Assert\\' => array($vendorDir . '/webmozart/assert/src'),

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitddf510289ef549bb5ae140bb78df7cba
class ComposerAutoloaderInitfca18ff1edd9fce0f35bc4b9397ad687
{
private static $loader;
@ -22,19 +22,19 @@ class ComposerAutoloaderInitddf510289ef549bb5ae140bb78df7cba
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitddf510289ef549bb5ae140bb78df7cba', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitfca18ff1edd9fce0f35bc4b9397ad687', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitddf510289ef549bb5ae140bb78df7cba', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitfca18ff1edd9fce0f35bc4b9397ad687', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitddf510289ef549bb5ae140bb78df7cba::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitfca18ff1edd9fce0f35bc4b9397ad687::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInitddf510289ef549bb5ae140bb78df7cba::$files;
$includeFiles = \Composer\Autoload\ComposerStaticInitfca18ff1edd9fce0f35bc4b9397ad687::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequireddf510289ef549bb5ae140bb78df7cba($fileIdentifier, $file);
composerRequirefca18ff1edd9fce0f35bc4b9397ad687($fileIdentifier, $file);
}
return $loader;
@ -46,7 +46,7 @@ class ComposerAutoloaderInitddf510289ef549bb5ae140bb78df7cba
* @param string $file
* @return void
*/
function composerRequireddf510289ef549bb5ae140bb78df7cba($fileIdentifier, $file)
function composerRequirefca18ff1edd9fce0f35bc4b9397ad687($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInitddf510289ef549bb5ae140bb78df7cba
class ComposerStaticInitfca18ff1edd9fce0f35bc4b9397ad687
{
public static $files = array (
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
@ -28,6 +28,7 @@ class ComposerStaticInitddf510289ef549bb5ae140bb78df7cba
),
'R' =>
array (
'Rector\\Utils\\' => 13,
'Rector\\Symfony\\' => 15,
'Rector\\Set\\' => 11,
'Rector\\RectorInstaller\\' => 23,
@ -38,7 +39,6 @@ class ComposerStaticInitddf510289ef549bb5ae140bb78df7cba
'Rector\\Laravel\\' => 15,
'Rector\\Doctrine\\' => 16,
'Rector\\Core\\' => 12,
'Rector\\Compiler\\' => 16,
'Rector\\CakePHP\\' => 15,
'Rector\\' => 7,
'RectorPrefix202206\\Webmozart\\Assert\\' => 36,
@ -99,6 +99,10 @@ class ComposerStaticInitddf510289ef549bb5ae140bb78df7cba
array (
0 => __DIR__ . '/..' . '/symfony/polyfill-intl-normalizer',
),
'Rector\\Utils\\' =>
array (
0 => __DIR__ . '/../..' . '/utils',
),
'Rector\\Symfony\\' =>
array (
0 => __DIR__ . '/..' . '/rector/rector-symfony/src',
@ -140,10 +144,6 @@ class ComposerStaticInitddf510289ef549bb5ae140bb78df7cba
array (
0 => __DIR__ . '/../..' . '/src',
),
'Rector\\Compiler\\' =>
array (
0 => __DIR__ . '/../..' . '/utils/compiler/src',
),
'Rector\\CakePHP\\' =>
array (
0 => __DIR__ . '/..' . '/rector/rector-cakephp/src',
@ -3417,9 +3417,9 @@ class ComposerStaticInitddf510289ef549bb5ae140bb78df7cba
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitddf510289ef549bb5ae140bb78df7cba::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitddf510289ef549bb5ae140bb78df7cba::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitddf510289ef549bb5ae140bb78df7cba::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitfca18ff1edd9fce0f35bc4b9397ad687::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitfca18ff1edd9fce0f35bc4b9397ad687::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitfca18ff1edd9fce0f35bc4b9397ad687::$classMap;
}, null, ClassLoader::class);
}