mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 05:48:21 +01:00
Updated Rector to commit 587d8d80585e20ce6455602ed12602e2bb7e9b71
587d8d8058
[Downgrade PHP 8.1] Add DowngradeReadonlyPropertyRector (#1262)
This commit is contained in:
parent
2ebb3ec25d
commit
976ae72f73
@ -1,3 +1,6 @@
|
||||
parameters:
|
||||
phpVersion: 80100
|
||||
|
||||
services:
|
||||
defaultAnalysisParser:
|
||||
factory: @cachedRectorParser
|
||||
|
@ -9,6 +9,7 @@ use Rector\DowngradePhp81\Rector\ClassConst\DowngradeFinalizePublicClassConstant
|
||||
use Rector\DowngradePhp81\Rector\FuncCall\DowngradeFirstClassCallableSyntaxRector;
|
||||
use Rector\DowngradePhp81\Rector\FunctionLike\DowngradeNeverTypeDeclarationRector;
|
||||
use Rector\DowngradePhp81\Rector\Instanceof_\DowngradePhp81ResourceReturnToObjectRector;
|
||||
use Rector\DowngradePhp81\Rector\Property\DowngradeReadonlyPropertyRector;
|
||||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
|
||||
return static function (\Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator $containerConfigurator) : void {
|
||||
$parameters = $containerConfigurator->parameters();
|
||||
@ -18,4 +19,5 @@ return static function (\Symfony\Component\DependencyInjection\Loader\Configurat
|
||||
$services->set(\Rector\DowngradePhp81\Rector\FuncCall\DowngradeFirstClassCallableSyntaxRector::class);
|
||||
$services->set(\Rector\DowngradePhp81\Rector\FunctionLike\DowngradeNeverTypeDeclarationRector::class);
|
||||
$services->set(\Rector\DowngradePhp81\Rector\Instanceof_\DowngradePhp81ResourceReturnToObjectRector::class);
|
||||
$services->set(\Rector\DowngradePhp81\Rector\Property\DowngradeReadonlyPropertyRector::class);
|
||||
};
|
||||
|
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\DowngradePhp81\Rector\Property;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
|
||||
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
||||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
||||
/**
|
||||
* @changelog https://wiki.php.net/rfc/readonly_properties_v2
|
||||
*
|
||||
* @see \Rector\Tests\DowngradePhp81\Rector\Property\DowngradeReadonlyPropertyRector\DowngradeReadonlyPropertyRectorTest
|
||||
*/
|
||||
final class DowngradeReadonlyPropertyRector extends \Rector\Core\Rector\AbstractRector
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private const TAGNAME = 'readonly';
|
||||
/**
|
||||
* @return array<class-string<Node>>
|
||||
*/
|
||||
public function getNodeTypes() : array
|
||||
{
|
||||
return [\PhpParser\Node\Stmt\Property::class, \PhpParser\Node\Param::class];
|
||||
}
|
||||
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
|
||||
{
|
||||
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Remove "readonly" property type, add a "@readonly" tag instead', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
public readonly string $foo;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->foo = 'foo';
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
, <<<'CODE_SAMPLE'
|
||||
class SomeClass
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
*/
|
||||
public string $foo;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->foo = 'foo';
|
||||
}
|
||||
}
|
||||
CODE_SAMPLE
|
||||
)]);
|
||||
}
|
||||
/**
|
||||
* @param Property|Param $node
|
||||
*/
|
||||
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
|
||||
{
|
||||
if (!$this->visibilityManipulator->isReadonly($node)) {
|
||||
return null;
|
||||
}
|
||||
if ($node instanceof \PhpParser\Node\Stmt\Property) {
|
||||
$this->addPhpDocTag($node);
|
||||
}
|
||||
$this->visibilityManipulator->removeReadonly($node);
|
||||
return $node;
|
||||
}
|
||||
private function addPhpDocTag(\PhpParser\Node\Stmt\Property $property) : void
|
||||
{
|
||||
$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($property);
|
||||
if ($phpDocInfo->hasByName(self::TAGNAME)) {
|
||||
return;
|
||||
}
|
||||
$phpDocInfo->addPhpDocTagNode(new \PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode('@' . self::TAGNAME, new \PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode('')));
|
||||
}
|
||||
}
|
@ -5,7 +5,6 @@ namespace Rector\Php81\Rector\Property;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Param;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\Property;
|
||||
use Rector\Core\NodeManipulator\PropertyManipulator;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
@ -101,7 +100,7 @@ CODE_SAMPLE
|
||||
if ($this->propertyManipulator->isPropertyChangeableExceptConstructor($param)) {
|
||||
return null;
|
||||
}
|
||||
if ($this->visibilityManipulator->hasVisibility($param, \PhpParser\Node\Stmt\Class_::MODIFIER_READONLY)) {
|
||||
if ($this->visibilityManipulator->isReadonly($param)) {
|
||||
return null;
|
||||
}
|
||||
$this->visibilityManipulator->makeReadonly($param);
|
||||
|
@ -125,7 +125,21 @@ final class VisibilityManipulator
|
||||
*/
|
||||
public function makeReadonly($node) : void
|
||||
{
|
||||
$this->addVisibilityFlag($node, \PhpParser\Node\Stmt\Class_::MODIFIER_READONLY);
|
||||
$this->addVisibilityFlag($node, \Rector\Core\ValueObject\Visibility::READONLY);
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Param|\PhpParser\Node\Stmt\Property $node
|
||||
*/
|
||||
public function isReadonly($node) : bool
|
||||
{
|
||||
return $this->hasVisibility($node, \Rector\Core\ValueObject\Visibility::READONLY);
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Param|\PhpParser\Node\Stmt\Property $node
|
||||
*/
|
||||
public function removeReadonly($node) : void
|
||||
{
|
||||
$this->removeVisibilityFlag($node, \Rector\Core\ValueObject\Visibility::READONLY);
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Param|\PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\ClassConst|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Property $node
|
||||
@ -134,6 +148,13 @@ final class VisibilityManipulator
|
||||
{
|
||||
$node->flags |= $visibility;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Param|\PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\ClassConst|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Property $node
|
||||
*/
|
||||
private function removeVisibilityFlag($node, int $visibility) : void
|
||||
{
|
||||
$node->flags &= ~$visibility;
|
||||
}
|
||||
/**
|
||||
* @param \PhpParser\Node\Stmt\ClassConst|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Property $node
|
||||
*/
|
||||
|
@ -16,11 +16,11 @@ final class VersionResolver
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '1258576514aa7c0d0b611c00fcae571d780077da';
|
||||
public const PACKAGE_VERSION = '587d8d80585e20ce6455602ed12602e2bb7e9b71';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2021-11-18 18:44:23';
|
||||
public const RELEASE_DATE = '2021-11-18 20:04:50';
|
||||
public static function resolvePackageVersion() : string
|
||||
{
|
||||
$process = new \RectorPrefix20211118\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);
|
||||
|
@ -30,4 +30,8 @@ final class Visibility
|
||||
* @var int
|
||||
*/
|
||||
public const FINAL = \PhpParser\Node\Stmt\Class_::MODIFIER_FINAL;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public const READONLY = \PhpParser\Node\Stmt\Class_::MODIFIER_READONLY;
|
||||
}
|
||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -4,4 +4,4 @@
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInitdd516ad6f055956fc703c8bf548e5b56::getLoader();
|
||||
return ComposerAutoloaderInitcb8a3884e2a1d755e219a4422b6f2dec::getLoader();
|
||||
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
@ -1888,6 +1888,7 @@ return array(
|
||||
'Rector\\DowngradePhp81\\Rector\\FuncCall\\DowngradeFirstClassCallableSyntaxRector' => $baseDir . '/rules/DowngradePhp81/Rector/FuncCall/DowngradeFirstClassCallableSyntaxRector.php',
|
||||
'Rector\\DowngradePhp81\\Rector\\FunctionLike\\DowngradeNeverTypeDeclarationRector' => $baseDir . '/rules/DowngradePhp81/Rector/FunctionLike/DowngradeNeverTypeDeclarationRector.php',
|
||||
'Rector\\DowngradePhp81\\Rector\\Instanceof_\\DowngradePhp81ResourceReturnToObjectRector' => $baseDir . '/rules/DowngradePhp81/Rector/Instanceof_/DowngradePhp81ResourceReturnToObjectRector.php',
|
||||
'Rector\\DowngradePhp81\\Rector\\Property\\DowngradeReadonlyPropertyRector' => $baseDir . '/rules/DowngradePhp81/Rector/Property/DowngradeReadonlyPropertyRector.php',
|
||||
'Rector\\EarlyReturn\\NodeFactory\\InvertedIfFactory' => $baseDir . '/rules/EarlyReturn/NodeFactory/InvertedIfFactory.php',
|
||||
'Rector\\EarlyReturn\\NodeTransformer\\ConditionInverter' => $baseDir . '/rules/EarlyReturn/NodeTransformer/ConditionInverter.php',
|
||||
'Rector\\EarlyReturn\\Rector\\Foreach_\\ChangeNestedForeachIfsToEarlyContinueRector' => $baseDir . '/rules/EarlyReturn/Rector/Foreach_/ChangeNestedForeachIfsToEarlyContinueRector.php',
|
||||
|
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 ComposerAutoloaderInitdd516ad6f055956fc703c8bf548e5b56
|
||||
class ComposerAutoloaderInitcb8a3884e2a1d755e219a4422b6f2dec
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,15 +22,15 @@ class ComposerAutoloaderInitdd516ad6f055956fc703c8bf548e5b56
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInitdd516ad6f055956fc703c8bf548e5b56', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInitcb8a3884e2a1d755e219a4422b6f2dec', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitdd516ad6f055956fc703c8bf548e5b56', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInitcb8a3884e2a1d755e219a4422b6f2dec', '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\ComposerStaticInitdd516ad6f055956fc703c8bf548e5b56::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInitcb8a3884e2a1d755e219a4422b6f2dec::getInitializer($loader));
|
||||
} else {
|
||||
$classMap = require __DIR__ . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
@ -42,19 +42,19 @@ class ComposerAutoloaderInitdd516ad6f055956fc703c8bf548e5b56
|
||||
$loader->register(true);
|
||||
|
||||
if ($useStaticLoader) {
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInitdd516ad6f055956fc703c8bf548e5b56::$files;
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInitcb8a3884e2a1d755e219a4422b6f2dec::$files;
|
||||
} else {
|
||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||
}
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequiredd516ad6f055956fc703c8bf548e5b56($fileIdentifier, $file);
|
||||
composerRequirecb8a3884e2a1d755e219a4422b6f2dec($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
||||
|
||||
function composerRequiredd516ad6f055956fc703c8bf548e5b56($fileIdentifier, $file)
|
||||
function composerRequirecb8a3884e2a1d755e219a4422b6f2dec($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
require $file;
|
||||
|
9
vendor/composer/autoload_static.php
vendored
9
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInitdd516ad6f055956fc703c8bf548e5b56
|
||||
class ComposerStaticInitcb8a3884e2a1d755e219a4422b6f2dec
|
||||
{
|
||||
public static $files = array (
|
||||
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
|
||||
@ -2218,6 +2218,7 @@ class ComposerStaticInitdd516ad6f055956fc703c8bf548e5b56
|
||||
'Rector\\DowngradePhp81\\Rector\\FuncCall\\DowngradeFirstClassCallableSyntaxRector' => __DIR__ . '/../..' . '/rules/DowngradePhp81/Rector/FuncCall/DowngradeFirstClassCallableSyntaxRector.php',
|
||||
'Rector\\DowngradePhp81\\Rector\\FunctionLike\\DowngradeNeverTypeDeclarationRector' => __DIR__ . '/../..' . '/rules/DowngradePhp81/Rector/FunctionLike/DowngradeNeverTypeDeclarationRector.php',
|
||||
'Rector\\DowngradePhp81\\Rector\\Instanceof_\\DowngradePhp81ResourceReturnToObjectRector' => __DIR__ . '/../..' . '/rules/DowngradePhp81/Rector/Instanceof_/DowngradePhp81ResourceReturnToObjectRector.php',
|
||||
'Rector\\DowngradePhp81\\Rector\\Property\\DowngradeReadonlyPropertyRector' => __DIR__ . '/../..' . '/rules/DowngradePhp81/Rector/Property/DowngradeReadonlyPropertyRector.php',
|
||||
'Rector\\EarlyReturn\\NodeFactory\\InvertedIfFactory' => __DIR__ . '/../..' . '/rules/EarlyReturn/NodeFactory/InvertedIfFactory.php',
|
||||
'Rector\\EarlyReturn\\NodeTransformer\\ConditionInverter' => __DIR__ . '/../..' . '/rules/EarlyReturn/NodeTransformer/ConditionInverter.php',
|
||||
'Rector\\EarlyReturn\\Rector\\Foreach_\\ChangeNestedForeachIfsToEarlyContinueRector' => __DIR__ . '/../..' . '/rules/EarlyReturn/Rector/Foreach_/ChangeNestedForeachIfsToEarlyContinueRector.php',
|
||||
@ -3556,9 +3557,9 @@ class ComposerStaticInitdd516ad6f055956fc703c8bf548e5b56
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitdd516ad6f055956fc703c8bf548e5b56::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitdd516ad6f055956fc703c8bf548e5b56::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitdd516ad6f055956fc703c8bf548e5b56::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInitcb8a3884e2a1d755e219a4422b6f2dec::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInitcb8a3884e2a1d755e219a4422b6f2dec::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInitcb8a3884e2a1d755e219a4422b6f2dec::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
10
vendor/scoper-autoload.php
vendored
10
vendor/scoper-autoload.php
vendored
@ -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('RectorPrefix20211118\AutoloadIncluder');
|
||||
}
|
||||
if (!class_exists('ComposerAutoloaderInitdd516ad6f055956fc703c8bf548e5b56', false) && !interface_exists('ComposerAutoloaderInitdd516ad6f055956fc703c8bf548e5b56', false) && !trait_exists('ComposerAutoloaderInitdd516ad6f055956fc703c8bf548e5b56', false)) {
|
||||
spl_autoload_call('RectorPrefix20211118\ComposerAutoloaderInitdd516ad6f055956fc703c8bf548e5b56');
|
||||
if (!class_exists('ComposerAutoloaderInitcb8a3884e2a1d755e219a4422b6f2dec', false) && !interface_exists('ComposerAutoloaderInitcb8a3884e2a1d755e219a4422b6f2dec', false) && !trait_exists('ComposerAutoloaderInitcb8a3884e2a1d755e219a4422b6f2dec', false)) {
|
||||
spl_autoload_call('RectorPrefix20211118\ComposerAutoloaderInitcb8a3884e2a1d755e219a4422b6f2dec');
|
||||
}
|
||||
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('RectorPrefix20211118\Helmich\TypoScriptParser\Parser\AST\Statement');
|
||||
@ -81,9 +81,9 @@ if (!function_exists('print_node')) {
|
||||
return \RectorPrefix20211118\print_node(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('composerRequiredd516ad6f055956fc703c8bf548e5b56')) {
|
||||
function composerRequiredd516ad6f055956fc703c8bf548e5b56() {
|
||||
return \RectorPrefix20211118\composerRequiredd516ad6f055956fc703c8bf548e5b56(...func_get_args());
|
||||
if (!function_exists('composerRequirecb8a3884e2a1d755e219a4422b6f2dec')) {
|
||||
function composerRequirecb8a3884e2a1d755e219a4422b6f2dec() {
|
||||
return \RectorPrefix20211118\composerRequirecb8a3884e2a1d755e219a4422b6f2dec(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('parseArgs')) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user