Skip to content

Commit

Permalink
Normalize array values in PhpAttributeGroupFactory (#190)
Browse files Browse the repository at this point in the history
  • Loading branch information
romainallanot committed Jun 9, 2021
1 parent e50ad80 commit c469fac
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
13 changes: 8 additions & 5 deletions packages/PhpAttribute/Printer/PhpAttributeGroupFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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
{
}
Expand Down

0 comments on commit c469fac

Please sign in to comment.