diff --git a/build/target-repository/docs/rector_rules_overview.md b/build/target-repository/docs/rector_rules_overview.md index 7b8a46364ec..f1c8acb72f6 100644 --- a/build/target-repository/docs/rector_rules_overview.md +++ b/build/target-repository/docs/rector_rules_overview.md @@ -1,4 +1,4 @@ -# 376 Rules Overview +# 374 Rules Overview
@@ -40,7 +40,7 @@ - [Php74](#php74) (13) -- [Php80](#php80) (18) +- [Php80](#php80) (17) - [Php81](#php81) (11) @@ -56,7 +56,7 @@ - [Strict](#strict) (5) -- [Transform](#transform) (26) +- [Transform](#transform) (25) - [TypeDeclaration](#typedeclaration) (40) @@ -5335,47 +5335,6 @@ return static function (RectorConfig $rectorConfig): void {
-### DoctrineAnnotationClassToAttributeRector - -Refactor Doctrine `@annotation` annotated class to a PHP 8.0 attribute class - -:wrench: **configure it!** - -- class: [`Rector\Php80\Rector\Class_\DoctrineAnnotationClassToAttributeRector`](../rules/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector.php) - -```php -ruleWithConfiguration(DoctrineAnnotationClassToAttributeRector::class, [ - DoctrineAnnotationClassToAttributeRector::REMOVE_ANNOTATIONS => true, - ]); -}; -``` - -↓ - -```diff --use Doctrine\Common\Annotations\Annotation\Target; -+use Attribute; - --/** -- * @Annotation -- * @Target({"METHOD"}) -- */ -+#[Attribute(Attribute::TARGET_METHOD)] - class SomeAnnotation - { - } -``` - -
- ### FinalPrivateToPrivateVisibilityRector Changes method visibility from final private to only private @@ -7480,42 +7439,6 @@ return static function (RectorConfig $rectorConfig): void {
-### RemoveAllowDynamicPropertiesAttributeRector - -Remove the `AllowDynamicProperties` attribute from all classes - -:wrench: **configure it!** - -- class: [`Rector\Transform\Rector\Class_\RemoveAllowDynamicPropertiesAttributeRector`](../rules/Transform/Rector/Class_/RemoveAllowDynamicPropertiesAttributeRector.php) - -```php -ruleWithConfiguration(RemoveAllowDynamicPropertiesAttributeRector::class, [ - 'Example\*', - ]); -}; -``` - -↓ - -```diff - namespace Example\Domain; - --#[AllowDynamicProperties] - class SomeObject { - public string $someProperty = 'hello world'; - } -``` - -
- ### ReplaceParentCallByPropertyCallRector Changes method calls in child of specific types to defined property method call diff --git a/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php b/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php index fd9e83e3cea..8765c177253 100644 --- a/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php +++ b/packages/BetterPhpDocParser/PhpDocInfo/PhpDocInfo.php @@ -245,23 +245,6 @@ public function hasByAnnotationClasses(array $annotationsClasses): bool return $this->getByAnnotationClasses($annotationsClasses) instanceof DoctrineAnnotationTagValueNode; } - /** - * @param string[] $desiredClasses - */ - public function findOneByAnnotationClasses(array $desiredClasses): ?DoctrineAnnotationTagValueNode - { - foreach ($desiredClasses as $desiredClass) { - $doctrineAnnotationTagValueNode = $this->findOneByAnnotationClass($desiredClass); - if (! $doctrineAnnotationTagValueNode instanceof DoctrineAnnotationTagValueNode) { - continue; - } - - return $doctrineAnnotationTagValueNode; - } - - return null; - } - public function findOneByAnnotationClass(string $desiredClass): ?DoctrineAnnotationTagValueNode { $foundTagValueNodes = $this->findByAnnotationClass($desiredClass); diff --git a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/DoctrineAnnotationClassToAttributeRectorTest.php b/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/DoctrineAnnotationClassToAttributeRectorTest.php deleted file mode 100644 index b0719949795..00000000000 --- a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/DoctrineAnnotationClassToAttributeRectorTest.php +++ /dev/null @@ -1,28 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configured_rule.php'; - } -} diff --git a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/fully_qualified_target.php.inc b/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/fully_qualified_target.php.inc deleted file mode 100644 index af4d34757a6..00000000000 --- a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/fully_qualified_target.php.inc +++ /dev/null @@ -1,24 +0,0 @@ - ------ - diff --git a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/none_target.php.inc b/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/none_target.php.inc deleted file mode 100644 index 221f8b1a614..00000000000 --- a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/none_target.php.inc +++ /dev/null @@ -1,23 +0,0 @@ - ------ - diff --git a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/required_value.php.inc b/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/required_value.php.inc deleted file mode 100644 index 63e14c2dcd7..00000000000 --- a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/required_value.php.inc +++ /dev/null @@ -1,32 +0,0 @@ - ------ - diff --git a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/short_target.php.inc b/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/short_target.php.inc deleted file mode 100644 index a8341a728e8..00000000000 --- a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/short_target.php.inc +++ /dev/null @@ -1,24 +0,0 @@ - ------ - diff --git a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/some_class.php.inc b/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/some_class.php.inc deleted file mode 100644 index 89a9e48bd03..00000000000 --- a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/some_class.php.inc +++ /dev/null @@ -1,28 +0,0 @@ - ------ - diff --git a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/target_method_only.php.inc b/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/target_method_only.php.inc deleted file mode 100644 index 83f2f771e40..00000000000 --- a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/target_method_only.php.inc +++ /dev/null @@ -1,28 +0,0 @@ - ------ - diff --git a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/target_method_property_class.php.inc b/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/target_method_property_class.php.inc deleted file mode 100644 index 8e03841811d..00000000000 --- a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/target_method_property_class.php.inc +++ /dev/null @@ -1,28 +0,0 @@ - ------ - diff --git a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/target_property.php.inc b/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/target_property.php.inc deleted file mode 100644 index 5913c8d379a..00000000000 --- a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/Fixture/target_property.php.inc +++ /dev/null @@ -1,28 +0,0 @@ - ------ - diff --git a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/FixtureShouldNotRemoveAnnotation/required_keep_old.php.inc b/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/FixtureShouldNotRemoveAnnotation/required_keep_old.php.inc deleted file mode 100644 index 595cc6175f8..00000000000 --- a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/FixtureShouldNotRemoveAnnotation/required_keep_old.php.inc +++ /dev/null @@ -1,38 +0,0 @@ - ------ -requiredField = $requiredField; - } -} - -?> diff --git a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/FixtureShouldNotRemoveAnnotation/skip_already_added.php.inc b/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/FixtureShouldNotRemoveAnnotation/skip_already_added.php.inc deleted file mode 100644 index 873cc9eea95..00000000000 --- a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/FixtureShouldNotRemoveAnnotation/skip_already_added.php.inc +++ /dev/null @@ -1,13 +0,0 @@ - ------ -requiredField = $requiredField; - } -} - -?> diff --git a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/FixtureShouldNotRemoveAnnotationDirectConfig/skip_already_added.php.inc b/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/FixtureShouldNotRemoveAnnotationDirectConfig/skip_already_added.php.inc deleted file mode 100644 index 873cc9eea95..00000000000 --- a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/FixtureShouldNotRemoveAnnotationDirectConfig/skip_already_added.php.inc +++ /dev/null @@ -1,13 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/FixtureShouldNotRemoveAnnotationDirectConfig'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/configure_direct_shouldnot_remove_annotation.php'; - } -} diff --git a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/ShouldNotRemoveAnnotationRectorTest.php b/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/ShouldNotRemoveAnnotationRectorTest.php deleted file mode 100644 index a4caf846d79..00000000000 --- a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/ShouldNotRemoveAnnotationRectorTest.php +++ /dev/null @@ -1,28 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFilesFromDirectory(__DIR__ . '/FixtureShouldNotRemoveAnnotation'); - } - - public function provideConfigFilePath(): string - { - return __DIR__ . '/config/should_not_remove_annotation.php'; - } -} diff --git a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/config/configure_direct_shouldnot_remove_annotation.php b/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/config/configure_direct_shouldnot_remove_annotation.php deleted file mode 100644 index f8afda25987..00000000000 --- a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/config/configure_direct_shouldnot_remove_annotation.php +++ /dev/null @@ -1,11 +0,0 @@ -ruleWithConfiguration(DoctrineAnnotationClassToAttributeRector::class, [false]); -}; diff --git a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/config/configured_rule.php b/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/config/configured_rule.php deleted file mode 100644 index 4ec75f1c75e..00000000000 --- a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/config/configured_rule.php +++ /dev/null @@ -1,10 +0,0 @@ -rule(DoctrineAnnotationClassToAttributeRector::class); -}; diff --git a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/config/should_not_remove_annotation.php b/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/config/should_not_remove_annotation.php deleted file mode 100644 index 1331185cf01..00000000000 --- a/rules-tests/Php80/Rector/Class_/DoctrineAnnotationClassToAttributeRector/config/should_not_remove_annotation.php +++ /dev/null @@ -1,13 +0,0 @@ -ruleWithConfiguration(DoctrineAnnotationClassToAttributeRector::class, [ - DoctrineAnnotationClassToAttributeRector::REMOVE_ANNOTATIONS => false, - ]); -}; diff --git a/rules/Php80/NodeAnalyzer/AnnotationTargetResolver.php b/rules/Php80/NodeAnalyzer/AnnotationTargetResolver.php deleted file mode 100644 index 711161ca47e..00000000000 --- a/rules/Php80/NodeAnalyzer/AnnotationTargetResolver.php +++ /dev/null @@ -1,57 +0,0 @@ - - */ - private const TARGET_TO_CONSTANT_MAP = [ - 'METHOD' => 'TARGET_METHOD', - 'PROPERTY' => 'TARGET_PROPERTY', - 'CLASS' => 'TARGET_CLASS', - 'FUNCTION' => 'TARGET_FUNCTION', - 'ALL' => 'TARGET_ALL', - // special case - 'ANNOTATION' => 'TARGET_CLASS', - ]; - - public function __construct( - private readonly NodeFactory $nodeFactory, - ) { - } - - /** - * @param ArrayItemNode[] $targetValues - * @return ClassConstFetch[] - */ - public function resolveFlagClassConstFetches(array $targetValues): array - { - $classConstFetches = []; - - foreach ($targetValues as $targetValue) { - foreach (self::TARGET_TO_CONSTANT_MAP as $target => $constant) { - if (! $targetValue->value instanceof StringNode) { - continue; - } - - if ($target !== $targetValue->value->value) { - continue; - } - - $classConstFetches[] = $this->nodeFactory->createClassConstFetch('Attribute', $constant); - } - } - - return $classConstFetches; - } -} diff --git a/rules/Php80/NodeFactory/AttributeFlagFactory.php b/rules/Php80/NodeFactory/AttributeFlagFactory.php deleted file mode 100644 index 12f1c353bd8..00000000000 --- a/rules/Php80/NodeFactory/AttributeFlagFactory.php +++ /dev/null @@ -1,30 +0,0 @@ - true, - ] - ), - ]); - } - - /** - * @return array> - */ - public function getNodeTypes(): array - { - return [Class_::class]; - } - - /** - * @param Class_ $node - */ - public function refactor(Node $node): ?Node - { - $phpDocInfo = $this->phpDocInfoFactory->createFromNode($node); - if (! $phpDocInfo instanceof PhpDocInfo) { - return null; - } - - if ($this->shouldSkipClass($phpDocInfo, $node)) { - return null; - } - - if ($this->shouldRemoveAnnotations) { - $this->phpDocTagRemover->removeByName($phpDocInfo, 'annotation'); - $this->phpDocTagRemover->removeByName($phpDocInfo, 'Annotation'); - } - - $attributeGroup = $this->phpAttributeGroupFactory->createFromClass(AttributeName::ATTRIBUTE); - $this->decorateTarget($phpDocInfo, $attributeGroup); - - foreach ($node->stmts as $key => $stmt) { - if (! $stmt instanceof Property) { - continue; - } - - $property = $stmt; - - $propertyPhpDocInfo = $this->phpDocInfoFactory->createFromNode($property); - if (! $propertyPhpDocInfo instanceof PhpDocInfo) { - continue; - } - - $requiredDoctrineAnnotationTagValueNode = $propertyPhpDocInfo->findOneByAnnotationClass( - 'Doctrine\Common\Annotations\Annotation\Required' - ); - if (! $requiredDoctrineAnnotationTagValueNode instanceof DoctrineAnnotationTagValueNode) { - continue; - } - - if ($this->shouldRemoveAnnotations) { - $this->phpDocTagRemover->removeTagValueFromNode( - $propertyPhpDocInfo, - $requiredDoctrineAnnotationTagValueNode - ); - } - - // require in constructor - $propertyName = $this->getName($property); - - $propertyMetadata = new PropertyMetadata($propertyName, new MixedType(), Class_::MODIFIER_PUBLIC); - $this->propertyToAddCollector->addPropertyToClass($node, $propertyMetadata); - - if ($this->shouldRemoveAnnotations) { - unset($node->stmts[$key]); - } - } - - $node->attrGroups[] = $attributeGroup; - - return $node; - } - - /** - * @param mixed[] $configuration - */ - public function configure(array $configuration): void - { - $shouldRemoveAnnotations = $configuration[self::REMOVE_ANNOTATIONS] ?? (bool) current($configuration); - Assert::boolean($shouldRemoveAnnotations); - $this->shouldRemoveAnnotations = $shouldRemoveAnnotations; - } - - private function decorateTarget(PhpDocInfo $phpDocInfo, AttributeGroup $attributeGroup): void - { - $targetDoctrineAnnotationTagValueNode = $phpDocInfo->findOneByAnnotationClasses([ - 'Doctrine\Common\Annotations\Annotation\Target', - 'Target', - ]); - - if (! $targetDoctrineAnnotationTagValueNode instanceof DoctrineAnnotationTagValueNode) { - return; - } - - if ($this->shouldRemoveAnnotations) { - $this->phpDocTagRemover->removeTagValueFromNode($phpDocInfo, $targetDoctrineAnnotationTagValueNode); - } - - $targetValues = $this->resolveTargetValues($targetDoctrineAnnotationTagValueNode); - if ($targetValues === []) { - return; - } - - $flagClassConstFetches = $this->annotationTargetResolver->resolveFlagClassConstFetches($targetValues); - - $flagCollection = $this->attributeFlagFactory->createFlagCollection($flagClassConstFetches); - if ($flagCollection === null) { - return; - } - - $attributeGroup->attrs[0]->args[] = new Arg($flagCollection); - } - - private function shouldSkipClass(PhpDocInfo $phpDocInfo, Class_ $class): bool - { - if (! $phpDocInfo->hasByNames(['Annotation', 'annotation'])) { - return true; - } - - // has attribute? skip it - return $this->phpAttributeAnalyzer->hasPhpAttribute($class, AttributeName::ATTRIBUTE); - } - - /** - * @return ArrayItemNode[] - */ - private function resolveTargetValues(DoctrineAnnotationTagValueNode $targetDoctrineAnnotationTagValueNode): array - { - $silentTargetsArrayItemNode = $targetDoctrineAnnotationTagValueNode->getSilentValue(); - if ($silentTargetsArrayItemNode instanceof ArrayItemNode) { - if ($silentTargetsArrayItemNode->value instanceof CurlyListNode) { - return $silentTargetsArrayItemNode->value->getValues(); - } - - return [$silentTargetsArrayItemNode]; - } - - return []; - } -} diff --git a/rules/Php81/Enum/AttributeName.php b/rules/Php81/Enum/AttributeName.php index 2c43dcd7618..b53e1972650 100644 --- a/rules/Php81/Enum/AttributeName.php +++ b/rules/Php81/Enum/AttributeName.php @@ -13,11 +13,6 @@ final class AttributeName */ public const RETURN_TYPE_WILL_CHANGE = 'ReturnTypeWillChange'; - /** - * @var string - */ - public const ATTRIBUTE = 'Attribute'; - /** * @var string */