diff --git a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/open_api_property_example_keep_numeric_string.php.inc b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/open_api_property_example_keep_numeric_string.php.inc new file mode 100644 index 00000000000..bec8fb1d448 --- /dev/null +++ b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/open_api_property_example_keep_numeric_string.php.inc @@ -0,0 +1,31 @@ + +----- + diff --git a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/config/configured_rule.php b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/config/configured_rule.php index 99e1e5e1a56..90f45bd5ed6 100644 --- a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/config/configured_rule.php +++ b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/config/configured_rule.php @@ -71,5 +71,8 @@ 'Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Source\Attribute\OpenApi\Annotation\SomeProperty', 'Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Source\Attribute\OpenApi\Attribute\SomeProperty' ), + + // for testing allow numeric string keep as string + new AnnotationToAttribute('OpenApi\\Annotations\\Property', 'OpenApi\\Attributes\\Property'), ]); }; diff --git a/src/PhpAttribute/AttributeArrayNameInliner.php b/src/PhpAttribute/AttributeArrayNameInliner.php index cd9d429f977..e98f0ca736d 100644 --- a/src/PhpAttribute/AttributeArrayNameInliner.php +++ b/src/PhpAttribute/AttributeArrayNameInliner.php @@ -15,14 +15,19 @@ final class AttributeArrayNameInliner { + /** + * @var class-string + */ + private const OPEN_API_PROPERTY_ATTRIBUTE = 'OpenApi\Attributes\Property'; + /** * @param Array_|list $array * @return list */ - public function inlineArrayToArgs(Array_|array $array): array + public function inlineArrayToArgs(Array_|array $array, ?string $attributeClass = null): array { if (is_array($array)) { - return $this->inlineArray($array); + return $this->inlineArray($array, $attributeClass); } return $this->inlineArrayNode($array); @@ -56,11 +61,16 @@ private function inlineArrayNode(Array_ $array): array * @param list $args * @return list */ - private function inlineArray(array $args): array + private function inlineArray(array $args, ?string $attributeClass = null): array { Assert::allIsAOf($args, Arg::class); - foreach ($args as $arg) { + if ($attributeClass === self::OPEN_API_PROPERTY_ATTRIBUTE + && $arg->name instanceof Identifier + && $arg->name->toString() === 'example') { + continue; + } + if ($arg->value instanceof String_ && is_numeric($arg->value->value)) { // use equal over identical on purpose to verify if it is an integer if ((float) $arg->value->value == (int) $arg->value->value) { diff --git a/src/PhpAttribute/NodeFactory/PhpAttributeGroupFactory.php b/src/PhpAttribute/NodeFactory/PhpAttributeGroupFactory.php index 23151cf79f4..847b748b01b 100644 --- a/src/PhpAttribute/NodeFactory/PhpAttributeGroupFactory.php +++ b/src/PhpAttribute/NodeFactory/PhpAttributeGroupFactory.php @@ -85,7 +85,7 @@ public function create( $this->annotationToAttributeIntegerValueCaster->castAttributeTypes($annotationToAttribute, $args); - $args = $this->attributeArrayNameInliner->inlineArrayToArgs($args); + $args = $this->attributeArrayNameInliner->inlineArrayToArgs($args, $annotationToAttribute->getAttributeClass()); $attributeName = $this->attributeNameFactory->create( $annotationToAttribute, diff --git a/stubs/OpenApi/Attributes/Property.php b/stubs/OpenApi/Attributes/Property.php new file mode 100644 index 00000000000..8f1cc81d3f1 --- /dev/null +++ b/stubs/OpenApi/Attributes/Property.php @@ -0,0 +1,17 @@ +