Updated Rector to commit aebd3118751ebf1bf21e300b6de2ee35052a01ef

aebd311875 Remove RemoveAllowDynamicPropertiesAttributeRector as attribute is a comment on lower PHP versions, also rather downgrade rule (#4120)
This commit is contained in:
Tomas Votruba 2023-06-08 18:34:29 +00:00
parent b9a2e1cfb3
commit fdf6a88b62
6 changed files with 12 additions and 122 deletions

View File

@ -1,108 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Transform\Rector\Class_;
use PhpParser\Node;
use PhpParser\Node\Stmt\Class_;
use Rector\Core\Contract\Rector\AllowEmptyConfigurableRectorInterface;
use Rector\Core\Rector\AbstractRector;
use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer;
use Rector\Php81\Enum\AttributeName;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use RectorPrefix202306\Webmozart\Assert\Assert;
/**
* @deprecated rather for downgrade-php, but still a comment, so not useful
* @changelog https://wiki.php.net/rfc/deprecate_dynamic_properties
*
* @see \Rector\Tests\Transform\Rector\Class_\RemoveAllowDynamicPropertiesAttributeRector\RemoveAllowDynamicPropertiesAttributeRectorTest
*/
final class RemoveAllowDynamicPropertiesAttributeRector extends AbstractRector implements AllowEmptyConfigurableRectorInterface
{
/**
* @var array<array-key, string>
*/
private $transformOnNamespaces = [];
/**
* @readonly
* @var \Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer
*/
private $phpAttributeAnalyzer;
public function __construct(PhpAttributeAnalyzer $phpAttributeAnalyzer)
{
$this->phpAttributeAnalyzer = $phpAttributeAnalyzer;
}
public function getRuleDefinition() : RuleDefinition
{
return new RuleDefinition('Remove the `AllowDynamicProperties` attribute from all classes', [new ConfiguredCodeSample(<<<'CODE_SAMPLE'
namespace Example\Domain;
#[AllowDynamicProperties]
class SomeObject {
public string $someProperty = 'hello world';
}
CODE_SAMPLE
, <<<'CODE_SAMPLE'
namespace Example\Domain;
class SomeObject {
public string $someProperty = 'hello world';
}
CODE_SAMPLE
, ['Example\\*'])]);
}
/**
* @return array<class-string<Node>>
*/
public function getNodeTypes() : array
{
return [Class_::class];
}
public function configure(array $configuration) : void
{
$transformOnNamespaces = $configuration;
Assert::allString($transformOnNamespaces);
$this->transformOnNamespaces = $transformOnNamespaces;
}
/**
* @param Class_ $node
*/
public function refactor(Node $node) : ?Node
{
if ($this->shouldRemove($node)) {
return $this->removeAllowDynamicPropertiesAttribute($node);
}
return null;
}
private function removeAllowDynamicPropertiesAttribute(Class_ $class) : Class_
{
$newAttrGroups = [];
foreach ($class->attrGroups as $attrGroup) {
$newAttrs = [];
foreach ($attrGroup->attrs as $attribute) {
if (!$this->nodeNameResolver->isName($attribute, AttributeName::ALLOW_DYNAMIC_PROPERTIES)) {
$newAttrs[] = $attribute;
}
}
$attrGroup->attrs = $newAttrs;
if ($attrGroup->attrs !== []) {
$newAttrGroups[] = $attrGroup;
}
}
$class->attrGroups = $newAttrGroups;
return $class;
}
private function shouldRemove(Class_ $class) : bool
{
if ($this->transformOnNamespaces !== []) {
$className = (string) $this->nodeNameResolver->getName($class);
foreach ($this->transformOnNamespaces as $transformOnNamespace) {
if (!$this->nodeNameResolver->isStringName($className, $transformOnNamespace)) {
return \false;
}
}
}
return $this->phpAttributeAnalyzer->hasPhpAttribute($class, AttributeName::ALLOW_DYNAMIC_PROPERTIES);
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '923b590fd5aca0b1fd7033963332d3c3845af1c7';
public const PACKAGE_VERSION = 'aebd3118751ebf1bf21e300b6de2ee35052a01ef';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-06-08 18:28:22';
public const RELEASE_DATE = '2023-06-08 18:29:34';
/**
* @var int
*/

2
vendor/autoload.php vendored
View File

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

View File

@ -2746,7 +2746,6 @@ return array(
'Rector\\Transform\\Rector\\Class_\\AddInterfaceByTraitRector' => $baseDir . '/rules/Transform/Rector/Class_/AddInterfaceByTraitRector.php',
'Rector\\Transform\\Rector\\Class_\\MergeInterfacesRector' => $baseDir . '/rules/Transform/Rector/Class_/MergeInterfacesRector.php',
'Rector\\Transform\\Rector\\Class_\\ParentClassToTraitsRector' => $baseDir . '/rules/Transform/Rector/Class_/ParentClassToTraitsRector.php',
'Rector\\Transform\\Rector\\Class_\\RemoveAllowDynamicPropertiesAttributeRector' => $baseDir . '/rules/Transform/Rector/Class_/RemoveAllowDynamicPropertiesAttributeRector.php',
'Rector\\Transform\\Rector\\FuncCall\\FuncCallToConstFetchRector' => $baseDir . '/rules/Transform/Rector/FuncCall/FuncCallToConstFetchRector.php',
'Rector\\Transform\\Rector\\FuncCall\\FuncCallToMethodCallRector' => $baseDir . '/rules/Transform/Rector/FuncCall/FuncCallToMethodCallRector.php',
'Rector\\Transform\\Rector\\FuncCall\\FuncCallToNewRector' => $baseDir . '/rules/Transform/Rector/FuncCall/FuncCallToNewRector.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit92e784fdb40f0a66f208716c00fafcdf
class ComposerAutoloaderInit62a997d020fa8aa397f1889e702be299
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit92e784fdb40f0a66f208716c00fafcdf
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit92e784fdb40f0a66f208716c00fafcdf', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit62a997d020fa8aa397f1889e702be299', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit92e784fdb40f0a66f208716c00fafcdf', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit62a997d020fa8aa397f1889e702be299', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit92e784fdb40f0a66f208716c00fafcdf::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit62a997d020fa8aa397f1889e702be299::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit92e784fdb40f0a66f208716c00fafcdf::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit62a997d020fa8aa397f1889e702be299::$files;
$requireFile = \Closure::bind(static function ($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 ComposerStaticInit92e784fdb40f0a66f208716c00fafcdf
class ComposerStaticInit62a997d020fa8aa397f1889e702be299
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -2997,7 +2997,6 @@ class ComposerStaticInit92e784fdb40f0a66f208716c00fafcdf
'Rector\\Transform\\Rector\\Class_\\AddInterfaceByTraitRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/Class_/AddInterfaceByTraitRector.php',
'Rector\\Transform\\Rector\\Class_\\MergeInterfacesRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/Class_/MergeInterfacesRector.php',
'Rector\\Transform\\Rector\\Class_\\ParentClassToTraitsRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/Class_/ParentClassToTraitsRector.php',
'Rector\\Transform\\Rector\\Class_\\RemoveAllowDynamicPropertiesAttributeRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/Class_/RemoveAllowDynamicPropertiesAttributeRector.php',
'Rector\\Transform\\Rector\\FuncCall\\FuncCallToConstFetchRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/FuncCall/FuncCallToConstFetchRector.php',
'Rector\\Transform\\Rector\\FuncCall\\FuncCallToMethodCallRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/FuncCall/FuncCallToMethodCallRector.php',
'Rector\\Transform\\Rector\\FuncCall\\FuncCallToNewRector' => __DIR__ . '/../..' . '/rules/Transform/Rector/FuncCall/FuncCallToNewRector.php',
@ -3157,9 +3156,9 @@ class ComposerStaticInit92e784fdb40f0a66f208716c00fafcdf
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit92e784fdb40f0a66f208716c00fafcdf::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit92e784fdb40f0a66f208716c00fafcdf::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit92e784fdb40f0a66f208716c00fafcdf::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit62a997d020fa8aa397f1889e702be299::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit62a997d020fa8aa397f1889e702be299::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit62a997d020fa8aa397f1889e702be299::$classMap;
}, null, ClassLoader::class);
}