From f177e0c3dd73404e1ee4fff32e5f04c0488c2f83 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Fri, 19 Aug 2022 07:49:30 +0000 Subject: [PATCH] Updated Rector to commit 76dc886f7a7f13fbed51e102ce4b616106f42702 https://github.com/rectorphp/rector-src/commit/76dc886f7a7f13fbed51e102ce4b616106f42702 Cleanup, re-use AttributeName enums (#2792) --- .../PhpDoc/DoctrineAnnotationTagValueNode.php | 12 ------------ .../Class_/AttributeCompatibleAnnotationRector.php | 7 ++----- .../DoctrineAnnotationClassToAttributeRector.php | 9 +++------ rules/Php81/Enum/AttributeName.php | 8 ++++++++ rules/Php82/Rector/Class_/ReadOnlyClassRector.php | 7 ++----- .../AddAllowDynamicPropertiesAttributeRector.php | 11 ++++------- ...RemoveAllowDynamicPropertiesAttributeRector.php | 9 +++------ src/Application/VersionResolver.php | 4 ++-- vendor/autoload.php | 2 +- vendor/composer/autoload_real.php | 14 +++++++------- vendor/composer/autoload_static.php | 8 ++++---- 11 files changed, 36 insertions(+), 55 deletions(-) diff --git a/packages/BetterPhpDocParser/PhpDoc/DoctrineAnnotationTagValueNode.php b/packages/BetterPhpDocParser/PhpDoc/DoctrineAnnotationTagValueNode.php index 379e409527c..a9339d37ac3 100644 --- a/packages/BetterPhpDocParser/PhpDoc/DoctrineAnnotationTagValueNode.php +++ b/packages/BetterPhpDocParser/PhpDoc/DoctrineAnnotationTagValueNode.php @@ -40,18 +40,6 @@ final class DoctrineAnnotationTagValueNode extends AbstractValuesAwareNode $itemContents = $this->printValuesContent($this->values); return \sprintf('(%s)', $itemContents); } - /** - * @param string[] $classNames - */ - public function hasClassNames(array $classNames) : bool - { - foreach ($classNames as $className) { - if ($this->hasClassName($className)) { - return \true; - } - } - return \false; - } public function hasClassName(string $className) : bool { $annotationName = \trim($this->identifierTypeNode->name, '@'); diff --git a/rules/Compatibility/Rector/Class_/AttributeCompatibleAnnotationRector.php b/rules/Compatibility/Rector/Class_/AttributeCompatibleAnnotationRector.php index eef90dc545f..6b034e0dc5a 100644 --- a/rules/Compatibility/Rector/Class_/AttributeCompatibleAnnotationRector.php +++ b/rules/Compatibility/Rector/Class_/AttributeCompatibleAnnotationRector.php @@ -17,6 +17,7 @@ use Rector\Compatibility\NodeFactory\ConstructorClassMethodFactory; use Rector\Compatibility\ValueObject\PropertyWithPhpDocInfo; use Rector\Core\Rector\AbstractRector; use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer; +use Rector\Php81\Enum\AttributeName; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** @@ -24,10 +25,6 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; */ final class AttributeCompatibleAnnotationRector extends AbstractRector { - /** - * @var string - */ - private const ATTRIBUTE = 'Attribute'; /** * @readonly * @var \Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer @@ -140,7 +137,7 @@ CODE_SAMPLE return \true; } // has attribute? skip it - return $this->phpAttributeAnalyzer->hasPhpAttribute($class, self::ATTRIBUTE); + return $this->phpAttributeAnalyzer->hasPhpAttribute($class, AttributeName::ATTRIBUTE); } /** * @param PropertyWithPhpDocInfo[] $requiredPropertiesWithPhpDocInfos diff --git a/rules/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector.php b/rules/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector.php index 1fc2ef4fa5e..a5c4c35426e 100644 --- a/rules/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector.php +++ b/rules/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector.php @@ -18,6 +18,7 @@ use Rector\Core\ValueObject\PhpVersionFeature; use Rector\Php80\NodeAnalyzer\AnnotationTargetResolver; use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer; use Rector\Php80\NodeFactory\AttributeFlagFactory; +use Rector\Php81\Enum\AttributeName; use Rector\PhpAttribute\NodeFactory\PhpAttributeGroupFactory; use Rector\PostRector\Collector\PropertyToAddCollector; use Rector\PostRector\ValueObject\PropertyMetadata; @@ -40,10 +41,6 @@ final class DoctrineAnnotationClassToAttributeRector extends AbstractRector impl * @var string */ public const REMOVE_ANNOTATIONS = 'remove_annotations'; - /** - * @var string - */ - private const ATTRIBUTE = 'Attribute'; /** * @var bool */ @@ -137,7 +134,7 @@ CODE_SAMPLE $this->phpDocTagRemover->removeByName($phpDocInfo, 'annotation'); $this->phpDocTagRemover->removeByName($phpDocInfo, 'Annotation'); } - $attributeGroup = $this->phpAttributeGroupFactory->createFromClass(self::ATTRIBUTE); + $attributeGroup = $this->phpAttributeGroupFactory->createFromClass(AttributeName::ATTRIBUTE); $this->decorateTarget($phpDocInfo, $attributeGroup); foreach ($node->getProperties() as $property) { $propertyPhpDocInfo = $this->phpDocInfoFactory->createFromNode($property); @@ -201,6 +198,6 @@ CODE_SAMPLE return \true; } // has attribute? skip it - return $this->phpAttributeAnalyzer->hasPhpAttribute($class, self::ATTRIBUTE); + return $this->phpAttributeAnalyzer->hasPhpAttribute($class, AttributeName::ATTRIBUTE); } } diff --git a/rules/Php81/Enum/AttributeName.php b/rules/Php81/Enum/AttributeName.php index d662c621cc3..74c02d85163 100644 --- a/rules/Php81/Enum/AttributeName.php +++ b/rules/Php81/Enum/AttributeName.php @@ -11,4 +11,12 @@ final class AttributeName * @var string */ public const RETURN_TYPE_WILL_CHANGE = 'ReturnTypeWillChange'; + /** + * @var string + */ + public const ATTRIBUTE = 'Attribute'; + /** + * @var string + */ + public const ALLOW_DYNAMIC_PROPERTIES = 'AllowDynamicProperties'; } diff --git a/rules/Php82/Rector/Class_/ReadOnlyClassRector.php b/rules/Php82/Rector/Class_/ReadOnlyClassRector.php index 17bbf45e44f..2cce1a78d1a 100644 --- a/rules/Php82/Rector/Class_/ReadOnlyClassRector.php +++ b/rules/Php82/Rector/Class_/ReadOnlyClassRector.php @@ -14,6 +14,7 @@ use Rector\Core\ValueObject\MethodName; use Rector\Core\ValueObject\PhpVersionFeature; use Rector\Core\ValueObject\Visibility; use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer; +use Rector\Php81\Enum\AttributeName; use Rector\Privatization\NodeManipulator\VisibilityManipulator; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; @@ -25,10 +26,6 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; */ final class ReadOnlyClassRector extends AbstractRector implements MinPhpVersionInterface { - /** - * @var string - */ - private const ATTRIBUTE = 'AllowDynamicProperties'; /** * @readonly * @var \Rector\Core\NodeAnalyzer\ClassAnalyzer @@ -154,7 +151,7 @@ CODE_SAMPLE if (!$class->isFinal()) { return \true; } - return $this->phpAttributeAnalyzer->hasPhpAttribute($class, self::ATTRIBUTE); + return $this->phpAttributeAnalyzer->hasPhpAttribute($class, AttributeName::ALLOW_DYNAMIC_PROPERTIES); } /** * @param Param[] $params diff --git a/rules/Transform/Rector/Class_/AddAllowDynamicPropertiesAttributeRector.php b/rules/Transform/Rector/Class_/AddAllowDynamicPropertiesAttributeRector.php index 62c966d7af8..d69f3bb372a 100644 --- a/rules/Transform/Rector/Class_/AddAllowDynamicPropertiesAttributeRector.php +++ b/rules/Transform/Rector/Class_/AddAllowDynamicPropertiesAttributeRector.php @@ -13,6 +13,7 @@ use Rector\Core\ValueObject\MethodName; use Rector\Core\ValueObject\PhpVersionFeature; use Rector\FamilyTree\Reflection\FamilyRelationsAnalyzer; use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer; +use Rector\Php81\Enum\AttributeName; use Rector\PhpAttribute\NodeFactory\PhpAttributeGroupFactory; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; @@ -25,10 +26,6 @@ use RectorPrefix202208\Webmozart\Assert\Assert; */ final class AddAllowDynamicPropertiesAttributeRector extends AbstractRector implements AllowEmptyConfigurableRectorInterface, MinPhpVersionInterface { - /** - * @var string - */ - private const ATTRIBUTE = 'AllowDynamicProperties'; /** * @var array */ @@ -116,18 +113,18 @@ CODE_SAMPLE } private function hasNeededAttributeAlready(Class_ $class) : bool { - $nodeHasAttribute = $this->phpAttributeAnalyzer->hasPhpAttribute($class, self::ATTRIBUTE); + $nodeHasAttribute = $this->phpAttributeAnalyzer->hasPhpAttribute($class, AttributeName::ALLOW_DYNAMIC_PROPERTIES); if ($nodeHasAttribute) { return \true; } if (!$class->extends instanceof FullyQualified) { return \false; } - return $this->phpAttributeAnalyzer->hasInheritedPhpAttribute($class, self::ATTRIBUTE); + return $this->phpAttributeAnalyzer->hasInheritedPhpAttribute($class, AttributeName::ALLOW_DYNAMIC_PROPERTIES); } private function addAllowDynamicPropertiesAttribute(Class_ $class) : Class_ { - $class->attrGroups[] = $this->phpAttributeGroupFactory->createFromClass(self::ATTRIBUTE); + $class->attrGroups[] = $this->phpAttributeGroupFactory->createFromClass(AttributeName::ALLOW_DYNAMIC_PROPERTIES); return $class; } private function shouldSkip(Class_ $class) : bool diff --git a/rules/Transform/Rector/Class_/RemoveAllowDynamicPropertiesAttributeRector.php b/rules/Transform/Rector/Class_/RemoveAllowDynamicPropertiesAttributeRector.php index 4e6ebca719a..8f6e6daba3d 100644 --- a/rules/Transform/Rector/Class_/RemoveAllowDynamicPropertiesAttributeRector.php +++ b/rules/Transform/Rector/Class_/RemoveAllowDynamicPropertiesAttributeRector.php @@ -8,6 +8,7 @@ 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 RectorPrefix202208\Webmozart\Assert\Assert; @@ -18,10 +19,6 @@ use RectorPrefix202208\Webmozart\Assert\Assert; */ final class RemoveAllowDynamicPropertiesAttributeRector extends AbstractRector implements AllowEmptyConfigurableRectorInterface { - /** - * @var string - */ - private const ATTRIBUTE = 'AllowDynamicProperties'; /** * @var array */ @@ -83,7 +80,7 @@ CODE_SAMPLE foreach ($class->attrGroups as $attrGroup) { $newAttrs = []; foreach ($attrGroup->attrs as $attribute) { - if (!$this->nodeNameResolver->isName($attribute, self::ATTRIBUTE)) { + if (!$this->nodeNameResolver->isName($attribute, AttributeName::ALLOW_DYNAMIC_PROPERTIES)) { $newAttrs[] = $attribute; } } @@ -105,6 +102,6 @@ CODE_SAMPLE } } } - return $this->phpAttributeAnalyzer->hasPhpAttribute($class, self::ATTRIBUTE); + return $this->phpAttributeAnalyzer->hasPhpAttribute($class, AttributeName::ALLOW_DYNAMIC_PROPERTIES); } } diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index b8414fc7593..c143b3f1e6c 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -17,12 +17,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = 'fc8efa0fe446dd648d5d4d393e32ee06a8876837'; + public const PACKAGE_VERSION = '76dc886f7a7f13fbed51e102ce4b616106f42702'; /** * @api * @var string */ - public const RELEASE_DATE = '2022-08-19 09:18:16'; + public const RELEASE_DATE = '2022-08-19 07:45:32'; /** * @var int */ diff --git a/vendor/autoload.php b/vendor/autoload.php index 23a87c3a0c1..df806e9287f 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -9,4 +9,4 @@ if (PHP_VERSION_ID < 50600) { require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit9b88e2fade2c989a43020703f0872c92::getLoader(); +return ComposerAutoloaderInitd09c83098b54286960e859382fa042bb::getLoader(); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index 7b0ca7f82be..39303868428 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit9b88e2fade2c989a43020703f0872c92 +class ComposerAutoloaderInitd09c83098b54286960e859382fa042bb { private static $loader; @@ -22,19 +22,19 @@ class ComposerAutoloaderInit9b88e2fade2c989a43020703f0872c92 return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit9b88e2fade2c989a43020703f0872c92', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInitd09c83098b54286960e859382fa042bb', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__)); - spl_autoload_unregister(array('ComposerAutoloaderInit9b88e2fade2c989a43020703f0872c92', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInitd09c83098b54286960e859382fa042bb', 'loadClassLoader')); require __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit9b88e2fade2c989a43020703f0872c92::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInitd09c83098b54286960e859382fa042bb::getInitializer($loader)); $loader->setClassMapAuthoritative(true); $loader->register(true); - $includeFiles = \Composer\Autoload\ComposerStaticInit9b88e2fade2c989a43020703f0872c92::$files; + $includeFiles = \Composer\Autoload\ComposerStaticInitd09c83098b54286960e859382fa042bb::$files; foreach ($includeFiles as $fileIdentifier => $file) { - composerRequire9b88e2fade2c989a43020703f0872c92($fileIdentifier, $file); + composerRequired09c83098b54286960e859382fa042bb($fileIdentifier, $file); } return $loader; @@ -46,7 +46,7 @@ class ComposerAutoloaderInit9b88e2fade2c989a43020703f0872c92 * @param string $file * @return void */ -function composerRequire9b88e2fade2c989a43020703f0872c92($fileIdentifier, $file) +function composerRequired09c83098b54286960e859382fa042bb($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 394b0ee5b65..36ca9fa3681 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit9b88e2fade2c989a43020703f0872c92 +class ComposerStaticInitd09c83098b54286960e859382fa042bb { public static $files = array ( '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php', @@ -3252,9 +3252,9 @@ class ComposerStaticInit9b88e2fade2c989a43020703f0872c92 public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit9b88e2fade2c989a43020703f0872c92::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit9b88e2fade2c989a43020703f0872c92::$prefixDirsPsr4; - $loader->classMap = ComposerStaticInit9b88e2fade2c989a43020703f0872c92::$classMap; + $loader->prefixLengthsPsr4 = ComposerStaticInitd09c83098b54286960e859382fa042bb::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInitd09c83098b54286960e859382fa042bb::$prefixDirsPsr4; + $loader->classMap = ComposerStaticInitd09c83098b54286960e859382fa042bb::$classMap; }, null, ClassLoader::class); }