Updated Rector to commit 398608747315e1d7bc96571db73903b140d22ff3

3986087473 [DX] Extract ContainerConfiguratorImportsMerger (#2101)
This commit is contained in:
Tomas Votruba 2022-04-20 08:09:40 +00:00
parent c32676bea1
commit 5a03282dce
9 changed files with 103 additions and 62 deletions

View File

@ -9,7 +9,7 @@ use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Expression;
use Rector\NodeNameResolver\NodeNameResolver;
final class EmptyAssignRemover
final class ContainerConfiguratorEmptyAssignRemover
{
/**
* @readonly

View File

@ -0,0 +1,65 @@
<?php
declare (strict_types=1);
namespace Rector\DogFood\NodeManipulator;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Expression;
use Rector\Core\PhpParser\Node\NodeFactory;
use Rector\NodeNameResolver\NodeNameResolver;
final class ContainerConfiguratorImportsMerger
{
/**
* @var string
*/
private const RECTOR_CONFIG_VARIABLE = 'rectorConfig';
/**
* @readonly
* @var \Rector\NodeNameResolver\NodeNameResolver
*/
private $nodeNameResolver;
/**
* @readonly
* @var \Rector\Core\PhpParser\Node\NodeFactory
*/
private $nodeFactory;
public function __construct(\Rector\NodeNameResolver\NodeNameResolver $nodeNameResolver, \Rector\Core\PhpParser\Node\NodeFactory $nodeFactory)
{
$this->nodeNameResolver = $nodeNameResolver;
$this->nodeFactory = $nodeFactory;
}
public function merge(\PhpParser\Node\Expr\Closure $closure) : void
{
$setConstantFetches = [];
$lastImportKey = null;
foreach ($closure->getStmts() as $key => $stmt) {
if (!$stmt instanceof \PhpParser\Node\Stmt\Expression) {
continue;
}
$expr = $stmt->expr;
if (!$expr instanceof \PhpParser\Node\Expr\MethodCall) {
continue;
}
if (!$this->nodeNameResolver->isName($expr->name, 'import')) {
continue;
}
$importArg = $expr->getArgs();
$argValue = $importArg[0]->value;
if (!$argValue instanceof \PhpParser\Node\Expr\ClassConstFetch) {
continue;
}
$setConstantFetches[] = $argValue;
unset($closure->stmts[$key]);
$lastImportKey = $key;
}
if ($setConstantFetches === []) {
return;
}
$args = $this->nodeFactory->createArgs([$setConstantFetches]);
$setsMethodCall = new \PhpParser\Node\Expr\MethodCall(new \PhpParser\Node\Expr\Variable(self::RECTOR_CONFIG_VARIABLE), 'sets', $args);
$closure->stmts[$lastImportKey] = new \PhpParser\Node\Stmt\Expression($setsMethodCall);
}
}

View File

@ -5,7 +5,6 @@ namespace Rector\DogFood\Rector\Closure;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\Variable;
@ -13,11 +12,11 @@ use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\Expression;
use Rector\Core\Configuration\Option;
use Rector\Core\Rector\AbstractRector;
use Rector\DogFood\NodeAnalyzer\ContainerConfiguratorCallAnalyzer;
use Rector\DogFood\NodeManipulator\EmptyAssignRemover;
use Rector\DogFood\NodeManipulator\ContainerConfiguratorEmptyAssignRemover;
use Rector\DogFood\NodeManipulator\ContainerConfiguratorImportsMerger;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
@ -48,13 +47,19 @@ final class UpgradeRectorConfigRector extends \Rector\Core\Rector\AbstractRector
private $containerConfiguratorCallAnalyzer;
/**
* @readonly
* @var \Rector\DogFood\NodeManipulator\EmptyAssignRemover
* @var \Rector\DogFood\NodeManipulator\ContainerConfiguratorEmptyAssignRemover
*/
private $emptyAssignRemover;
public function __construct(\Rector\DogFood\NodeAnalyzer\ContainerConfiguratorCallAnalyzer $containerConfiguratorCallAnalyzer, \Rector\DogFood\NodeManipulator\EmptyAssignRemover $emptyAssignRemover)
private $containerConfiguratorEmptyAssignRemover;
/**
* @readonly
* @var \Rector\DogFood\NodeManipulator\ContainerConfiguratorImportsMerger
*/
private $containerConfiguratorImportsMerger;
public function __construct(\Rector\DogFood\NodeAnalyzer\ContainerConfiguratorCallAnalyzer $containerConfiguratorCallAnalyzer, \Rector\DogFood\NodeManipulator\ContainerConfiguratorEmptyAssignRemover $containerConfiguratorEmptyAssignRemover, \Rector\DogFood\NodeManipulator\ContainerConfiguratorImportsMerger $containerConfiguratorImportsMerger)
{
$this->containerConfiguratorCallAnalyzer = $containerConfiguratorCallAnalyzer;
$this->emptyAssignRemover = $emptyAssignRemover;
$this->containerConfiguratorEmptyAssignRemover = $containerConfiguratorEmptyAssignRemover;
$this->containerConfiguratorImportsMerger = $containerConfiguratorImportsMerger;
}
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
{
@ -111,7 +116,7 @@ CODE_SAMPLE
}
$this->updateClosureParam($onlyParam);
// 1. change import of sets to single sets() method call
$this->refactorSetImportMethodCalls($node);
$this->containerConfiguratorImportsMerger->merge($node);
$this->traverseNodesWithCallable($node->getStmts(), function (\PhpParser\Node $node) : ?MethodCall {
// 2. call on rule
if ($node instanceof \PhpParser\Node\Expr\MethodCall) {
@ -130,7 +135,7 @@ CODE_SAMPLE
}
return null;
});
$this->emptyAssignRemover->removeFromClosure($node);
$this->containerConfiguratorEmptyAssignRemover->removeFromClosure($node);
return $node;
}
public function updateClosureParam(\PhpParser\Node\Param $param) : void
@ -183,35 +188,4 @@ CODE_SAMPLE
}
return null;
}
private function refactorSetImportMethodCalls(\PhpParser\Node\Expr\Closure $closure) : void
{
$setConstantFetches = [];
$lastImportKey = null;
foreach ($closure->getStmts() as $key => $stmt) {
if (!$stmt instanceof \PhpParser\Node\Stmt\Expression) {
continue;
}
$expr = $stmt->expr;
if (!$expr instanceof \PhpParser\Node\Expr\MethodCall) {
continue;
}
if (!$this->isName($expr->name, 'import')) {
continue;
}
$importArg = $expr->getArgs();
$argValue = $importArg[0]->value;
if (!$argValue instanceof \PhpParser\Node\Expr\ClassConstFetch) {
continue;
}
$setConstantFetches[] = $argValue;
unset($closure->stmts[$key]);
$lastImportKey = $key;
}
if ($setConstantFetches === []) {
return;
}
$args = $this->nodeFactory->createArgs([$setConstantFetches]);
$setsMethodCall = new \PhpParser\Node\Expr\MethodCall(new \PhpParser\Node\Expr\Variable(self::RECTOR_CONFIG_VARIABLE), 'sets', $args);
$closure->stmts[$lastImportKey] = new \PhpParser\Node\Stmt\Expression($setsMethodCall);
}
}

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = 'de95ab646f579704328895648de12ca68813c16d';
public const PACKAGE_VERSION = '398608747315e1d7bc96571db73903b140d22ff3';
/**
* @var string
*/
public const RELEASE_DATE = '2022-04-20 07:37:06';
public const RELEASE_DATE = '2022-04-20 08:02:34';
/**
* @var string
*/

2
vendor/autoload.php vendored
View File

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

View File

@ -1956,7 +1956,8 @@ return array(
'Rector\\Doctrine\\ValueObject\\PropertyNameAndPhpDocInfo' => $vendorDir . '/rector/rector-doctrine/src/ValueObject/PropertyNameAndPhpDocInfo.php',
'Rector\\Doctrine\\ValueObject\\PropertyNamesAndPhpDocInfos' => $vendorDir . '/rector/rector-doctrine/src/ValueObject/PropertyNamesAndPhpDocInfos.php',
'Rector\\DogFood\\NodeAnalyzer\\ContainerConfiguratorCallAnalyzer' => $baseDir . '/rules/DogFood/NodeAnalyzer/ContainerConfiguratorCallAnalyzer.php',
'Rector\\DogFood\\NodeManipulator\\EmptyAssignRemover' => $baseDir . '/rules/DogFood/NodeManipulator/EmptyAssignRemover.php',
'Rector\\DogFood\\NodeManipulator\\ContainerConfiguratorEmptyAssignRemover' => $baseDir . '/rules/DogFood/NodeManipulator/ContainerConfiguratorEmptyAssignRemover.php',
'Rector\\DogFood\\NodeManipulator\\ContainerConfiguratorImportsMerger' => $baseDir . '/rules/DogFood/NodeManipulator/ContainerConfiguratorImportsMerger.php',
'Rector\\DogFood\\Rector\\Closure\\UpgradeRectorConfigRector' => $baseDir . '/rules/DogFood/Rector/Closure/UpgradeRectorConfigRector.php',
'Rector\\DowngradePhp53\\Rector\\Dir\\DirConstToFileConstRector' => $baseDir . '/rules/DowngradePhp53/Rector/Dir/DirConstToFileConstRector.php',
'Rector\\DowngradePhp54\\Rector\\Array_\\ShortArrayToLongArrayRector' => $baseDir . '/rules/DowngradePhp54/Rector/Array_/ShortArrayToLongArrayRector.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit6f71e4087747ab68470221dd9fd618ae
class ComposerAutoloaderInit09afb76b48dfed1b2a031423216a4206
{
private static $loader;
@ -22,19 +22,19 @@ class ComposerAutoloaderInit6f71e4087747ab68470221dd9fd618ae
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit6f71e4087747ab68470221dd9fd618ae', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit09afb76b48dfed1b2a031423216a4206', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit6f71e4087747ab68470221dd9fd618ae', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit09afb76b48dfed1b2a031423216a4206', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit6f71e4087747ab68470221dd9fd618ae::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit09afb76b48dfed1b2a031423216a4206::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$includeFiles = \Composer\Autoload\ComposerStaticInit6f71e4087747ab68470221dd9fd618ae::$files;
$includeFiles = \Composer\Autoload\ComposerStaticInit09afb76b48dfed1b2a031423216a4206::$files;
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire6f71e4087747ab68470221dd9fd618ae($fileIdentifier, $file);
composerRequire09afb76b48dfed1b2a031423216a4206($fileIdentifier, $file);
}
return $loader;
@ -46,7 +46,7 @@ class ComposerAutoloaderInit6f71e4087747ab68470221dd9fd618ae
* @param string $file
* @return void
*/
function composerRequire6f71e4087747ab68470221dd9fd618ae($fileIdentifier, $file)
function composerRequire09afb76b48dfed1b2a031423216a4206($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 ComposerStaticInit6f71e4087747ab68470221dd9fd618ae
class ComposerStaticInit09afb76b48dfed1b2a031423216a4206
{
public static $files = array (
'320cde22f66dd4f5d3fd621d3e88b98f' => __DIR__ . '/..' . '/symfony/polyfill-ctype/bootstrap.php',
@ -2325,7 +2325,8 @@ class ComposerStaticInit6f71e4087747ab68470221dd9fd618ae
'Rector\\Doctrine\\ValueObject\\PropertyNameAndPhpDocInfo' => __DIR__ . '/..' . '/rector/rector-doctrine/src/ValueObject/PropertyNameAndPhpDocInfo.php',
'Rector\\Doctrine\\ValueObject\\PropertyNamesAndPhpDocInfos' => __DIR__ . '/..' . '/rector/rector-doctrine/src/ValueObject/PropertyNamesAndPhpDocInfos.php',
'Rector\\DogFood\\NodeAnalyzer\\ContainerConfiguratorCallAnalyzer' => __DIR__ . '/../..' . '/rules/DogFood/NodeAnalyzer/ContainerConfiguratorCallAnalyzer.php',
'Rector\\DogFood\\NodeManipulator\\EmptyAssignRemover' => __DIR__ . '/../..' . '/rules/DogFood/NodeManipulator/EmptyAssignRemover.php',
'Rector\\DogFood\\NodeManipulator\\ContainerConfiguratorEmptyAssignRemover' => __DIR__ . '/../..' . '/rules/DogFood/NodeManipulator/ContainerConfiguratorEmptyAssignRemover.php',
'Rector\\DogFood\\NodeManipulator\\ContainerConfiguratorImportsMerger' => __DIR__ . '/../..' . '/rules/DogFood/NodeManipulator/ContainerConfiguratorImportsMerger.php',
'Rector\\DogFood\\Rector\\Closure\\UpgradeRectorConfigRector' => __DIR__ . '/../..' . '/rules/DogFood/Rector/Closure/UpgradeRectorConfigRector.php',
'Rector\\DowngradePhp53\\Rector\\Dir\\DirConstToFileConstRector' => __DIR__ . '/../..' . '/rules/DowngradePhp53/Rector/Dir/DirConstToFileConstRector.php',
'Rector\\DowngradePhp54\\Rector\\Array_\\ShortArrayToLongArrayRector' => __DIR__ . '/../..' . '/rules/DowngradePhp54/Rector/Array_/ShortArrayToLongArrayRector.php',
@ -3868,9 +3869,9 @@ class ComposerStaticInit6f71e4087747ab68470221dd9fd618ae
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit6f71e4087747ab68470221dd9fd618ae::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit6f71e4087747ab68470221dd9fd618ae::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit6f71e4087747ab68470221dd9fd618ae::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit09afb76b48dfed1b2a031423216a4206::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit09afb76b48dfed1b2a031423216a4206::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit09afb76b48dfed1b2a031423216a4206::$classMap;
}, null, ClassLoader::class);
}

View File

@ -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('RectorPrefix20220420\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInit6f71e4087747ab68470221dd9fd618ae', false) && !interface_exists('ComposerAutoloaderInit6f71e4087747ab68470221dd9fd618ae', false) && !trait_exists('ComposerAutoloaderInit6f71e4087747ab68470221dd9fd618ae', false)) {
spl_autoload_call('RectorPrefix20220420\ComposerAutoloaderInit6f71e4087747ab68470221dd9fd618ae');
if (!class_exists('ComposerAutoloaderInit09afb76b48dfed1b2a031423216a4206', false) && !interface_exists('ComposerAutoloaderInit09afb76b48dfed1b2a031423216a4206', false) && !trait_exists('ComposerAutoloaderInit09afb76b48dfed1b2a031423216a4206', false)) {
spl_autoload_call('RectorPrefix20220420\ComposerAutoloaderInit09afb76b48dfed1b2a031423216a4206');
}
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('RectorPrefix20220420\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -59,9 +59,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20220420\print_node(...func_get_args());
}
}
if (!function_exists('composerRequire6f71e4087747ab68470221dd9fd618ae')) {
function composerRequire6f71e4087747ab68470221dd9fd618ae() {
return \RectorPrefix20220420\composerRequire6f71e4087747ab68470221dd9fd618ae(...func_get_args());
if (!function_exists('composerRequire09afb76b48dfed1b2a031423216a4206')) {
function composerRequire09afb76b48dfed1b2a031423216a4206() {
return \RectorPrefix20220420\composerRequire09afb76b48dfed1b2a031423216a4206(...func_get_args());
}
}
if (!function_exists('scanPath')) {