Updated Rector to commit dd7bc52135

dd7bc52135 Move ChangeGlobalVariablesToPropertiesRector from ClassMethod to Class_ node, to keep the minimal changed scope in active nodes (#1307)
This commit is contained in:
Tomas Votruba 2021-11-25 13:07:04 +00:00
parent 3830b5616f
commit cdff1edc5d
9 changed files with 34 additions and 35 deletions

View File

@ -3,11 +3,11 @@
declare (strict_types=1);
namespace RectorPrefix20211125;
use Rector\Privatization\Rector\Class_\ChangeGlobalVariablesToPropertiesRector;
use Rector\Privatization\Rector\Class_\ChangeLocalPropertyToVariableRector;
use Rector\Privatization\Rector\Class_\ChangeReadOnlyVariableWithDefaultValueToConstantRector;
use Rector\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenRector;
use Rector\Privatization\Rector\Class_\RepeatedLiteralToClassConstantRector;
use Rector\Privatization\Rector\ClassMethod\ChangeGlobalVariablesToPropertiesRector;
use Rector\Privatization\Rector\ClassMethod\PrivatizeFinalClassMethodRector;
use Rector\Privatization\Rector\MethodCall\PrivatizeLocalGetterToPropertyRector;
use Rector\Privatization\Rector\Property\ChangeReadOnlyPropertyWithDefaultValueToConstantRector;
@ -16,7 +16,7 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigura
return static function (\Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator $containerConfigurator) : void {
$services = $containerConfigurator->services();
$services->set(\Rector\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenRector::class);
$services->set(\Rector\Privatization\Rector\ClassMethod\ChangeGlobalVariablesToPropertiesRector::class);
$services->set(\Rector\Privatization\Rector\Class_\ChangeGlobalVariablesToPropertiesRector::class);
$services->set(\Rector\Privatization\Rector\Property\ChangeReadOnlyPropertyWithDefaultValueToConstantRector::class);
$services->set(\Rector\Privatization\Rector\Class_\ChangeReadOnlyVariableWithDefaultValueToConstantRector::class);
$services->set(\Rector\Privatization\Rector\Class_\RepeatedLiteralToClassConstantRector::class);

View File

@ -8883,7 +8883,7 @@ Add unique use imports collected during Rector run
Change global `$variables` to private properties
- class: [`Rector\Privatization\Rector\ClassMethod\ChangeGlobalVariablesToPropertiesRector`](../rules/Privatization/Rector/ClassMethod/ChangeGlobalVariablesToPropertiesRector.php)
- class: [`Rector\Privatization\Rector\Class_\ChangeGlobalVariablesToPropertiesRector`](../rules/Privatization/Rector/ClassMethod/ChangeGlobalVariablesToPropertiesRector.php)
```diff
class SomeClass

View File

@ -1,7 +1,7 @@
<?php
declare (strict_types=1);
namespace Rector\Privatization\Rector\ClassMethod;
namespace Rector\Privatization\Rector\Class_;
use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
@ -10,6 +10,7 @@ use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Global_;
use PhpParser\NodeTraverser;
use Rector\Core\Rector\AbstractRector;
use Rector\PostRector\Collector\PropertyToAddCollector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@ -18,7 +19,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
* @see https://3v4l.org/DWC4P
*
* @changelog https://stackoverflow.com/a/12446305/1348344
* @see \Rector\Tests\Privatization\Rector\ClassMethod\ChangeGlobalVariablesToPropertiesRector\ChangeGlobalVariablesToPropertiesRectorTest
* @see \Rector\Tests\Privatization\Rector\Class_\ChangeGlobalVariablesToPropertiesRector\ChangeGlobalVariablesToPropertiesRectorTest
*/
final class ChangeGlobalVariablesToPropertiesRector extends \Rector\Core\Rector\AbstractRector
{
@ -74,33 +75,31 @@ CODE_SAMPLE
*/
public function getNodeTypes() : array
{
return [\PhpParser\Node\Stmt\ClassMethod::class];
return [\PhpParser\Node\Stmt\Class_::class];
}
/**
* @param ClassMethod $node
* @param Class_ $node
*/
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
{
$classLike = $this->betterNodeFinder->findParentType($node, \PhpParser\Node\Stmt\Class_::class);
if (!$classLike instanceof \PhpParser\Node\Stmt\Class_) {
return null;
foreach ($node->getMethods() as $classMethod) {
$this->collectGlobalVariableNamesAndRefactorToPropertyFetch($node, $classMethod);
}
$this->collectGlobalVariableNamesAndRefactorToPropertyFetch($classLike, $node);
if ($this->globalVariableNames === []) {
return null;
}
foreach ($this->globalVariableNames as $globalVariableName) {
$this->propertyToAddCollector->addPropertyWithoutConstructorToClass($globalVariableName, null, $classLike);
$this->propertyToAddCollector->addPropertyWithoutConstructorToClass($globalVariableName, null, $node);
}
return $node;
}
private function collectGlobalVariableNamesAndRefactorToPropertyFetch(\PhpParser\Node\Stmt\Class_ $class, \PhpParser\Node\Stmt\ClassMethod $classMethod) : void
{
$this->globalVariableNames = [];
$this->traverseNodesWithCallable($classMethod, function (\PhpParser\Node $node) use($class) : ?PropertyFetch {
$this->traverseNodesWithCallable($classMethod, function (\PhpParser\Node $node) use($class) {
if ($node instanceof \PhpParser\Node\Stmt\Global_) {
$this->refactorGlobal($class, $node);
return null;
return \PhpParser\NodeTraverser::DONT_TRAVERSE_CHILDREN;
}
if ($node instanceof \PhpParser\Node\Expr\Variable) {
return $this->refactorGlobalVariable($node);

View File

@ -16,11 +16,11 @@ final class VersionResolver
/**
* @var string
*/
public const PACKAGE_VERSION = '62474db941673004057b8c5c76c3a74471396b0a';
public const PACKAGE_VERSION = 'dd7bc521353848643a1ab20ac5713f6afe50b30e';
/**
* @var string
*/
public const RELEASE_DATE = '2021-11-25 12:45:36';
public const RELEASE_DATE = '2021-11-25 13:49:59';
public static function resolvePackageVersion() : string
{
$process = new \RectorPrefix20211125\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInitf886a30e8d66cb95346cea3d74f2b584::getLoader();
return ComposerAutoloaderInit6ec690acecac2de5a5cbe8b2f6318b9e::getLoader();

View File

@ -2682,8 +2682,8 @@ return array(
'Rector\\Privatization\\NodeManipulator\\VisibilityManipulator' => $baseDir . '/rules/Privatization/NodeManipulator/VisibilityManipulator.php',
'Rector\\Privatization\\NodeReplacer\\PropertyFetchWithConstFetchReplacer' => $baseDir . '/rules/Privatization/NodeReplacer/PropertyFetchWithConstFetchReplacer.php',
'Rector\\Privatization\\NodeReplacer\\PropertyFetchWithVariableReplacer' => $baseDir . '/rules/Privatization/NodeReplacer/PropertyFetchWithVariableReplacer.php',
'Rector\\Privatization\\Rector\\ClassMethod\\ChangeGlobalVariablesToPropertiesRector' => $baseDir . '/rules/Privatization/Rector/ClassMethod/ChangeGlobalVariablesToPropertiesRector.php',
'Rector\\Privatization\\Rector\\ClassMethod\\PrivatizeFinalClassMethodRector' => $baseDir . '/rules/Privatization/Rector/ClassMethod/PrivatizeFinalClassMethodRector.php',
'Rector\\Privatization\\Rector\\Class_\\ChangeGlobalVariablesToPropertiesRector' => $baseDir . '/rules/Privatization/Rector/Class_/ChangeGlobalVariablesToPropertiesRector.php',
'Rector\\Privatization\\Rector\\Class_\\ChangeLocalPropertyToVariableRector' => $baseDir . '/rules/Privatization/Rector/Class_/ChangeLocalPropertyToVariableRector.php',
'Rector\\Privatization\\Rector\\Class_\\ChangeReadOnlyVariableWithDefaultValueToConstantRector' => $baseDir . '/rules/Privatization/Rector/Class_/ChangeReadOnlyVariableWithDefaultValueToConstantRector.php',
'Rector\\Privatization\\Rector\\Class_\\FinalizeClassesWithoutChildrenRector' => $baseDir . '/rules/Privatization/Rector/Class_/FinalizeClassesWithoutChildrenRector.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitf886a30e8d66cb95346cea3d74f2b584
class ComposerAutoloaderInit6ec690acecac2de5a5cbe8b2f6318b9e
{
private static $loader;
@ -22,15 +22,15 @@ class ComposerAutoloaderInitf886a30e8d66cb95346cea3d74f2b584
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitf886a30e8d66cb95346cea3d74f2b584', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit6ec690acecac2de5a5cbe8b2f6318b9e', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInitf886a30e8d66cb95346cea3d74f2b584', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit6ec690acecac2de5a5cbe8b2f6318b9e', '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\ComposerStaticInitf886a30e8d66cb95346cea3d74f2b584::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit6ec690acecac2de5a5cbe8b2f6318b9e::getInitializer($loader));
} else {
$classMap = require __DIR__ . '/autoload_classmap.php';
if ($classMap) {
@ -42,19 +42,19 @@ class ComposerAutoloaderInitf886a30e8d66cb95346cea3d74f2b584
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInitf886a30e8d66cb95346cea3d74f2b584::$files;
$includeFiles = Composer\Autoload\ComposerStaticInit6ec690acecac2de5a5cbe8b2f6318b9e::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequiref886a30e8d66cb95346cea3d74f2b584($fileIdentifier, $file);
composerRequire6ec690acecac2de5a5cbe8b2f6318b9e($fileIdentifier, $file);
}
return $loader;
}
}
function composerRequiref886a30e8d66cb95346cea3d74f2b584($fileIdentifier, $file)
function composerRequire6ec690acecac2de5a5cbe8b2f6318b9e($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
require $file;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInitf886a30e8d66cb95346cea3d74f2b584
class ComposerStaticInit6ec690acecac2de5a5cbe8b2f6318b9e
{
public static $files = array (
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
@ -3079,8 +3079,8 @@ class ComposerStaticInitf886a30e8d66cb95346cea3d74f2b584
'Rector\\Privatization\\NodeManipulator\\VisibilityManipulator' => __DIR__ . '/../..' . '/rules/Privatization/NodeManipulator/VisibilityManipulator.php',
'Rector\\Privatization\\NodeReplacer\\PropertyFetchWithConstFetchReplacer' => __DIR__ . '/../..' . '/rules/Privatization/NodeReplacer/PropertyFetchWithConstFetchReplacer.php',
'Rector\\Privatization\\NodeReplacer\\PropertyFetchWithVariableReplacer' => __DIR__ . '/../..' . '/rules/Privatization/NodeReplacer/PropertyFetchWithVariableReplacer.php',
'Rector\\Privatization\\Rector\\ClassMethod\\ChangeGlobalVariablesToPropertiesRector' => __DIR__ . '/../..' . '/rules/Privatization/Rector/ClassMethod/ChangeGlobalVariablesToPropertiesRector.php',
'Rector\\Privatization\\Rector\\ClassMethod\\PrivatizeFinalClassMethodRector' => __DIR__ . '/../..' . '/rules/Privatization/Rector/ClassMethod/PrivatizeFinalClassMethodRector.php',
'Rector\\Privatization\\Rector\\Class_\\ChangeGlobalVariablesToPropertiesRector' => __DIR__ . '/../..' . '/rules/Privatization/Rector/Class_/ChangeGlobalVariablesToPropertiesRector.php',
'Rector\\Privatization\\Rector\\Class_\\ChangeLocalPropertyToVariableRector' => __DIR__ . '/../..' . '/rules/Privatization/Rector/Class_/ChangeLocalPropertyToVariableRector.php',
'Rector\\Privatization\\Rector\\Class_\\ChangeReadOnlyVariableWithDefaultValueToConstantRector' => __DIR__ . '/../..' . '/rules/Privatization/Rector/Class_/ChangeReadOnlyVariableWithDefaultValueToConstantRector.php',
'Rector\\Privatization\\Rector\\Class_\\FinalizeClassesWithoutChildrenRector' => __DIR__ . '/../..' . '/rules/Privatization/Rector/Class_/FinalizeClassesWithoutChildrenRector.php',
@ -3764,9 +3764,9 @@ class ComposerStaticInitf886a30e8d66cb95346cea3d74f2b584
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitf886a30e8d66cb95346cea3d74f2b584::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitf886a30e8d66cb95346cea3d74f2b584::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitf886a30e8d66cb95346cea3d74f2b584::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit6ec690acecac2de5a5cbe8b2f6318b9e::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit6ec690acecac2de5a5cbe8b2f6318b9e::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit6ec690acecac2de5a5cbe8b2f6318b9e::$classMap;
}, null, ClassLoader::class);
}

View File

@ -12,8 +12,8 @@ if (!class_exists('GenerateChangelogCommand', false) && !interface_exists('Gener
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
spl_autoload_call('RectorPrefix20211125\AutoloadIncluder');
}
if (!class_exists('ComposerAutoloaderInitf886a30e8d66cb95346cea3d74f2b584', false) && !interface_exists('ComposerAutoloaderInitf886a30e8d66cb95346cea3d74f2b584', false) && !trait_exists('ComposerAutoloaderInitf886a30e8d66cb95346cea3d74f2b584', false)) {
spl_autoload_call('RectorPrefix20211125\ComposerAutoloaderInitf886a30e8d66cb95346cea3d74f2b584');
if (!class_exists('ComposerAutoloaderInit6ec690acecac2de5a5cbe8b2f6318b9e', false) && !interface_exists('ComposerAutoloaderInit6ec690acecac2de5a5cbe8b2f6318b9e', false) && !trait_exists('ComposerAutoloaderInit6ec690acecac2de5a5cbe8b2f6318b9e', false)) {
spl_autoload_call('RectorPrefix20211125\ComposerAutoloaderInit6ec690acecac2de5a5cbe8b2f6318b9e');
}
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('RectorPrefix20211125\Helmich\TypoScriptParser\Parser\AST\Statement');
@ -81,9 +81,9 @@ if (!function_exists('print_node')) {
return \RectorPrefix20211125\print_node(...func_get_args());
}
}
if (!function_exists('composerRequiref886a30e8d66cb95346cea3d74f2b584')) {
function composerRequiref886a30e8d66cb95346cea3d74f2b584() {
return \RectorPrefix20211125\composerRequiref886a30e8d66cb95346cea3d74f2b584(...func_get_args());
if (!function_exists('composerRequire6ec690acecac2de5a5cbe8b2f6318b9e')) {
function composerRequire6ec690acecac2de5a5cbe8b2f6318b9e() {
return \RectorPrefix20211125\composerRequire6ec690acecac2de5a5cbe8b2f6318b9e(...func_get_args());
}
}
if (!function_exists('parseArgs')) {