diff --git a/rules-tests/DowngradePhp80/Rector/Class_/DowngradeAttributeToAnnotationRector/Fixture/attribute_same_line.php.inc b/rules-tests/DowngradePhp80/Rector/Class_/DowngradeAttributeToAnnotationRector/Fixture/attribute_same_line.php.inc new file mode 100644 index 00000000..d8d6143c --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/Class_/DowngradeAttributeToAnnotationRector/Fixture/attribute_same_line.php.inc @@ -0,0 +1,28 @@ + +----- + diff --git a/rules-tests/DowngradePhp80/Rector/Class_/DowngradeAttributeToAnnotationRector/Fixture/with_override.php.inc b/rules-tests/DowngradePhp80/Rector/Class_/DowngradeAttributeToAnnotationRector/Fixture/with_override.php.inc new file mode 100644 index 00000000..384a0182 --- /dev/null +++ b/rules-tests/DowngradePhp80/Rector/Class_/DowngradeAttributeToAnnotationRector/Fixture/with_override.php.inc @@ -0,0 +1,26 @@ + +----- + diff --git a/rules/DowngradePhp80/Rector/Class_/DowngradeAttributeToAnnotationRector.php b/rules/DowngradePhp80/Rector/Class_/DowngradeAttributeToAnnotationRector.php index c20e2f00..6a776e27 100644 --- a/rules/DowngradePhp80/Rector/Class_/DowngradeAttributeToAnnotationRector.php +++ b/rules/DowngradePhp80/Rector/Class_/DowngradeAttributeToAnnotationRector.php @@ -34,7 +34,13 @@ final class DowngradeAttributeToAnnotationRector extends AbstractRector implemen /** * @var string[] */ - private const SKIPPED_ATTRIBUTES = ['Attribute', 'ReturnTypeWillChange', 'AllowDynamicProperties']; + private const SKIPPED_ATTRIBUTES = [ + 'Attribute', + 'ReturnTypeWillChange', + 'AllowDynamicProperties', + 'Override', + 'SensitiveParameter', + ]; /** * @var DowngradeAttributeToAnnotation[] @@ -114,8 +120,15 @@ public function refactor(Node $node): ?Node (string) $oldTokens[$attrGroup->getEndTokenPos() + 1], "\n" )) { + if ($node->getStartTokenPos() === strlen($attribute->name->toString()) - 2) { + $indentation = ''; + } else { + $indent = $attrGroup->getEndTokenPos() - $node->getStartTokenPos() + 2; + $indentation = $indent > 0 ? str_repeat(' ', $indent) : ''; + } + // add new line - $oldTokens[$attrGroup->getEndTokenPos() + 1]->text = "\n" . $oldTokens[$attrGroup->getEndTokenPos() + 1]->text; + $oldTokens[$attrGroup->getEndTokenPos() + 1]->text = "\n" . $indentation . $oldTokens[$attrGroup->getEndTokenPos() + 1]->text; $this->isDowngraded = true; }