diff --git a/packages/PhpAttribute/Printer/PhpAttributeGroupFactory.php b/packages/PhpAttribute/Printer/PhpAttributeGroupFactory.php index c3d56d7ebc9..1b5cdcb9678 100644 --- a/packages/PhpAttribute/Printer/PhpAttributeGroupFactory.php +++ b/packages/PhpAttribute/Printer/PhpAttributeGroupFactory.php @@ -107,11 +107,7 @@ private function normalizeNodeValue($value): bool | float | int | string | array return (int) $value->value; } - if ($value instanceof ConstantFloatType) { - return $value->getValue(); - } - - if ($value instanceof ConstantBooleanType) { + if ($value instanceof ConstantFloatType || $value instanceof ConstantBooleanType) { return $value->getValue(); } @@ -140,6 +136,13 @@ private function normalizeNodeValue($value): bool | float | int | string | array return (string) $value; } + if (\is_array($value)) { + return array_map( + fn ($item) => $this->normalizeNodeValue($item), + $value + ); + } + return $value; } } diff --git a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/api_platform_resource.php.inc b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/api_platform_resource.php.inc index bfe9234a847..669c0be38e1 100644 --- a/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/api_platform_resource.php.inc +++ b/rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/api_platform_resource.php.inc @@ -5,10 +5,24 @@ namespace Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Fixture; use ApiPlatform\Core\Annotation\ApiResource; /** - * @ApiResource(collectionOperations={}, itemOperations={ - * "get", - * "get_by_isbn"={"method"="GET", "path"="/books/by_isbn/{isbn}.{_format}", "requirements"={"isbn"=".+"}, "identifiers"="isbn"} - * }) + * @ApiResource( + * collectionOperations={}, + * itemOperations={ + * "get", + * "get_by_isbn"={"method"="GET", "path"="/books/by_isbn/{isbn}.{_format}", "requirements"={"isbn"=".+"}, "identifiers"="isbn"} + * }, + * graphql={ + * "sumOnlyPersist"={ + * "mutation"="app.graphql.mutation_resolver.dummy_custom_only_persist", + * "normalization_context"={"groups"={"result"}}, + * "denormalization_context"={"groups"={"sum"}}, + * "read"=false, + * "deserialize"=false, + * "validate"=false, + * "serialize"=false + * } + * } + * ) */ class ApiPlatformResource { @@ -22,7 +36,7 @@ namespace Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Fixture; use ApiPlatform\Core\Annotation\ApiResource; -#[\ApiPlatform\Core\Annotation\ApiResource(collectionOperations: [], itemOperations: ['get', 'get_by_isbn' => ['method' => 'GET', 'path' => '/books/by_isbn/{isbn}.{_format}', 'requirements' => ['isbn' => '.+'], 'identifiers' => 'isbn']])] +#[\ApiPlatform\Core\Annotation\ApiResource(collectionOperations: [], itemOperations: ['get', 'get_by_isbn' => ['method' => 'GET', 'path' => '/books/by_isbn/{isbn}.{_format}', 'requirements' => ['isbn' => '.+'], 'identifiers' => 'isbn']], graphql: ['sumOnlyPersist' => ['mutation' => 'app.graphql.mutation_resolver.dummy_custom_only_persist', 'normalization_context' => ['groups' => ['result']], 'denormalization_context' => ['groups' => ['sum']], 'read' => false, 'deserialize' => false, 'validate' => false, 'serialize' => false]])] class ApiPlatformResource { }