From a346b89ab895849ad5619dc7d7d299e039c79e1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Sun, 5 Sep 2021 15:31:56 +0200 Subject: [PATCH] fix: improve some types in the new attributes --- src/Metadata/ApiProperty.php | 16 ++--- src/Metadata/ApiResource.php | 108 +++++++++++++++++---------------- src/Metadata/Delete.php | 4 +- src/Metadata/Get.php | 2 +- src/Metadata/GetCollection.php | 4 +- src/Metadata/Operation.php | 14 +++-- src/Metadata/Patch.php | 4 +- src/Metadata/Post.php | 4 +- src/Metadata/Put.php | 4 +- 9 files changed, 84 insertions(+), 76 deletions(-) diff --git a/src/Metadata/ApiProperty.php b/src/Metadata/ApiProperty.php index 723cac3eaa3..9e64682b58e 100644 --- a/src/Metadata/ApiProperty.php +++ b/src/Metadata/ApiProperty.php @@ -294,7 +294,7 @@ public function withExample($example): self return $self; } - public function getDeprecationReason() + public function getDeprecationReason(): ?string { return $this->deprecationReason; } @@ -307,7 +307,7 @@ public function withDeprecationReason($deprecationReason): self return $self; } - public function isFetchable() + public function isFetchable(): ?bool { return $this->fetchable; } @@ -320,7 +320,7 @@ public function withFetchable($fetchable): self return $self; } - public function getFetchEager() + public function getFetchEager(): ?bool { return $this->fetchEager; } @@ -333,7 +333,7 @@ public function withFetchEager($fetchEager): self return $self; } - public function getJsonldContext() + public function getJsonldContext(): ?array { return $this->jsonldContext; } @@ -346,7 +346,7 @@ public function withJsonldContext($jsonldContext): self return $self; } - public function getOpenapiContext() + public function getOpenapiContext(): ?array { return $this->openapiContext; } @@ -359,7 +359,7 @@ public function withOpenapiContext($openapiContext): self return $self; } - public function getPush() + public function getPush(): ?bool { return $this->push; } @@ -372,7 +372,7 @@ public function withPush($push): self return $self; } - public function getSecurity() + public function getSecurity(): ?string { return $this->security; } @@ -385,7 +385,7 @@ public function withSecurity($security): self return $self; } - public function getSecurityPostDenormalize() + public function getSecurityPostDenormalize(): ?string { return $this->securityPostDenormalize; } diff --git a/src/Metadata/ApiResource.php b/src/Metadata/ApiResource.php index 3999fcc7e45..622063e960e 100644 --- a/src/Metadata/ApiResource.php +++ b/src/Metadata/ApiResource.php @@ -20,7 +20,7 @@ * @experimental */ #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)] -class ApiResource +final class ApiResource { private $operations; private $uriTemplate; @@ -110,56 +110,57 @@ class ApiResource private $extraProperties; /** - * @param string $uriTemplate - * @param string $shortName - * @param string $description - * @param array|string $formats https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation - * @param array|string $inputFormats https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation - * @param array|string $outputFormats https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation - * @param string $routePrefix https://api-platform.com/docs/core/operations/#prefixing-all-routes-of-all-operations - * @param bool $stateless - * @param string $sunset https://api-platform.com/docs/core/deprecations/#setting-the-sunset-http-header-to-indicate-when-a-resource-or-an-operation-will-be-removed - * @param string $acceptPatch - * @param string $status - * @param string $class - * @param int $urlGenerationStrategy - * @param string $deprecationReason https://api-platform.com/docs/core/deprecations/#deprecating-resource-classes-operations-and-properties - * @param array $cacheHeaders https://api-platform.com/docs/core/performance/#setting-custom-http-cache-headers - * @param array $normalizationContext https://api-platform.com/docs/core/serialization/#using-serialization-groups - * @param array $denormalizationContext https://api-platform.com/docs/core/serialization/#using-serialization-groups - * @param string[] $hydraContext https://api-platform.com/docs/core/extending-jsonld-context/#hydra - * @param array $openapiContext https://api-platform.com/docs/core/openapi/#using-the-openapi-and-swagger-contexts - * @param array $validationContext https://api-platform.com/docs/core/validation/#using-validation-groups - * @param string[] $filters https://api-platform.com/docs/core/filters/#doctrine-orm-and-mongodb-odm-filters - * @param bool $elasticsearch https://api-platform.com/docs/core/elasticsearch/ - * @param bool|array $mercure https://api-platform.com/docs/core/mercure - * @param bool $messenger https://api-platform.com/docs/core/messenger/#dispatching-a-resource-through-the-message-bus - * @param mixed $input https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation - * @param mixed $output https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation - * @param array $order https://api-platform.com/docs/core/default-order/#overriding-default-order - * @param bool $fetchPartial https://api-platform.com/docs/core/performance/#fetch-partial - * @param bool $forceEager https://api-platform.com/docs/core/performance/#force-eager - * @param bool $paginationClientEnabled https://api-platform.com/docs/core/pagination/#for-a-specific-resource-1 - * @param bool $paginationClientItemsPerPage https://api-platform.com/docs/core/pagination/#for-a-specific-resource-3 - * @param bool $paginationClientPartial https://api-platform.com/docs/core/pagination/#for-a-specific-resource-6 - * @param array $paginationViaCursor https://api-platform.com/docs/core/pagination/#cursor-based-pagination - * @param bool $paginationEnabled https://api-platform.com/docs/core/pagination/#for-a-specific-resource - * @param bool $paginationFetchJoinCollection https://api-platform.com/docs/core/pagination/#controlling-the-behavior-of-the-doctrine-orm-paginator - * @param int $paginationItemsPerPage https://api-platform.com/docs/core/pagination/#changing-the-number-of-items-per-page - * @param int $paginationMaximumItemsPerPage https://api-platform.com/docs/core/pagination/#changing-maximum-items-per-page - * @param bool $paginationPartial https://api-platform.com/docs/core/performance/#partial-pagination - * @param string $paginationType https://api-platform.com/docs/core/graphql/#using-the-page-based-pagination - * @param string $security https://api-platform.com/docs/core/security - * @param string $securityMessage https://api-platform.com/docs/core/security/#configuring-the-access-control-error-message - * @param string $securityPostDenormalize https://api-platform.com/docs/core/security/#executing-access-control-rules-after-denormalization - * @param string $securityPostDenormalizeMessage https://api-platform.com/docs/core/security/#configuring-the-access-control-error-message - * @param bool $compositeIdentifier + * @param string $uriTemplate + * @param string $shortName + * @param string $description + * @param string[]|string $types + * @param array|string $formats https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation + * @param array|string $inputFormats https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation + * @param array|string $outputFormats https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation + * @param string $routePrefix https://api-platform.com/docs/core/operations/#prefixing-all-routes-of-all-operations + * @param bool $stateless + * @param string $sunset https://api-platform.com/docs/core/deprecations/#setting-the-sunset-http-header-to-indicate-when-a-resource-or-an-operation-will-be-removed + * @param string $acceptPatch + * @param string $status + * @param string $class + * @param int $urlGenerationStrategy + * @param string $deprecationReason https://api-platform.com/docs/core/deprecations/#deprecating-resource-classes-operations-and-properties + * @param array $cacheHeaders https://api-platform.com/docs/core/performance/#setting-custom-http-cache-headers + * @param array $normalizationContext https://api-platform.com/docs/core/serialization/#using-serialization-groups + * @param array $denormalizationContext https://api-platform.com/docs/core/serialization/#using-serialization-groups + * @param string[] $hydraContext https://api-platform.com/docs/core/extending-jsonld-context/#hydra + * @param array $openapiContext https://api-platform.com/docs/core/openapi/#using-the-openapi-and-swagger-contexts + * @param array $validationContext https://api-platform.com/docs/core/validation/#using-validation-groups + * @param string[] $filters https://api-platform.com/docs/core/filters/#doctrine-orm-and-mongodb-odm-filters + * @param bool $elasticsearch https://api-platform.com/docs/core/elasticsearch/ + * @param bool|array $mercure https://api-platform.com/docs/core/mercure + * @param bool $messenger https://api-platform.com/docs/core/messenger/#dispatching-a-resource-through-the-message-bus + * @param mixed $input https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation + * @param mixed $output https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation + * @param array $order https://api-platform.com/docs/core/default-order/#overriding-default-order + * @param bool $fetchPartial https://api-platform.com/docs/core/performance/#fetch-partial + * @param bool $forceEager https://api-platform.com/docs/core/performance/#force-eager + * @param bool $paginationClientEnabled https://api-platform.com/docs/core/pagination/#for-a-specific-resource-1 + * @param bool $paginationClientItemsPerPage https://api-platform.com/docs/core/pagination/#for-a-specific-resource-3 + * @param bool $paginationClientPartial https://api-platform.com/docs/core/pagination/#for-a-specific-resource-6 + * @param array $paginationViaCursor https://api-platform.com/docs/core/pagination/#cursor-based-pagination + * @param bool $paginationEnabled https://api-platform.com/docs/core/pagination/#for-a-specific-resource + * @param bool $paginationFetchJoinCollection https://api-platform.com/docs/core/pagination/#controlling-the-behavior-of-the-doctrine-orm-paginator + * @param int $paginationItemsPerPage https://api-platform.com/docs/core/pagination/#changing-the-number-of-items-per-page + * @param int $paginationMaximumItemsPerPage https://api-platform.com/docs/core/pagination/#changing-maximum-items-per-page + * @param bool $paginationPartial https://api-platform.com/docs/core/performance/#partial-pagination + * @param string $paginationType https://api-platform.com/docs/core/graphql/#using-the-page-based-pagination + * @param string $security https://api-platform.com/docs/core/security + * @param string $securityMessage https://api-platform.com/docs/core/security/#configuring-the-access-control-error-message + * @param string $securityPostDenormalize https://api-platform.com/docs/core/security/#executing-access-control-rules-after-denormalization + * @param string $securityPostDenormalizeMessage https://api-platform.com/docs/core/security/#configuring-the-access-control-error-message + * @param bool $compositeIdentifier */ public function __construct( ?string $uriTemplate = null, ?string $shortName = null, ?string $description = null, - array $types = [], + $types = [], $operations = [], $formats = null, $inputFormats = null, @@ -220,7 +221,7 @@ public function __construct( $this->uriTemplate = $uriTemplate; $this->shortName = $shortName; $this->description = $description; - $this->types = $types; + $this->types = (array) $types; $this->formats = $formats; $this->inputFormats = $inputFormats; $this->outputFormats = $outputFormats; @@ -295,7 +296,7 @@ public function getUriTemplate(): ?string return $this->uriTemplate; } - public function withUriTemplate(?string $uriTemplate = null) + public function withUriTemplate(?string $uriTemplate = null): self { $self = clone $this; $self->uriTemplate = $uriTemplate; @@ -308,7 +309,7 @@ public function getShortName(): ?string return $this->shortName; } - public function withShortName(?string $shortName = null) + public function withShortName(?string $shortName = null): self { $self = clone $this; $self->shortName = $shortName; @@ -321,7 +322,7 @@ public function getDescription(): ?string return $this->description; } - public function withDescription(?string $description = null) + public function withDescription(?string $description = null): self { $self = clone $this; $self->description = $description; @@ -334,10 +335,13 @@ public function getTypes(): array return $this->types; } - public function withTypes(array $types = []) + /** + * @param string[]|string $types + */ + public function withTypes($types = []): self { $self = clone $this; - $self->types = $types; + $self->types = (array) $types; return $self; } diff --git a/src/Metadata/Delete.php b/src/Metadata/Delete.php index f9e114052d3..3baebec0d4a 100644 --- a/src/Metadata/Delete.php +++ b/src/Metadata/Delete.php @@ -14,7 +14,7 @@ namespace ApiPlatform\Metadata; #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)] -class Delete extends Operation +final class Delete extends Operation { /** * {@inheritdoc} @@ -24,7 +24,7 @@ public function __construct( ?string $uriTemplate = null, ?string $shortName = null, ?string $description = null, - array $types = [], + $types = [], $formats = null, $inputFormats = null, $outputFormats = null, diff --git a/src/Metadata/Get.php b/src/Metadata/Get.php index 6084edeec4e..0f50fdb8a79 100644 --- a/src/Metadata/Get.php +++ b/src/Metadata/Get.php @@ -23,7 +23,7 @@ public function __construct( ?string $uriTemplate = null, ?string $shortName = null, ?string $description = null, - array $types = [], + $types = [], $formats = null, $inputFormats = null, $outputFormats = null, diff --git a/src/Metadata/GetCollection.php b/src/Metadata/GetCollection.php index 9d2700eb781..9553bd88f3d 100644 --- a/src/Metadata/GetCollection.php +++ b/src/Metadata/GetCollection.php @@ -14,7 +14,7 @@ namespace ApiPlatform\Metadata; #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)] -class GetCollection extends Operation +final class GetCollection extends Operation { /** * {@inheritdoc} @@ -23,7 +23,7 @@ public function __construct( ?string $uriTemplate = null, ?string $shortName = null, ?string $description = null, - array $types = [], + $types = [], $formats = null, $inputFormats = null, $outputFormats = null, diff --git a/src/Metadata/Operation.php b/src/Metadata/Operation.php index 3ae808e275a..3e5037e753c 100644 --- a/src/Metadata/Operation.php +++ b/src/Metadata/Operation.php @@ -125,6 +125,7 @@ class Operation * @param string $uriTemplate * @param string $shortName * @param string $description + * @param string[]|string $types * @param array|string $formats https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation * @param array|string $inputFormats https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation * @param array|string $outputFormats https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation @@ -180,7 +181,7 @@ public function __construct( ?string $uriTemplate = null, ?string $shortName = null, ?string $description = null, - array $types = [], + $types = [], $formats = null, $inputFormats = null, $outputFormats = null, @@ -251,7 +252,7 @@ public function __construct( $this->uriTemplate = $uriTemplate; $this->shortName = $shortName; $this->description = $description; - $this->types = $types; + $this->types = (array) $types; $this->formats = $formats; $this->inputFormats = $inputFormats; $this->outputFormats = $outputFormats; @@ -367,7 +368,7 @@ public function getShortName(): ?string return $this->shortName; } - public function withShortName(?string $shortName = null) + public function withShortName(?string $shortName = null): self { $self = clone $this; $self->shortName = $shortName; @@ -380,7 +381,7 @@ public function getDescription(): ?string return $this->description; } - public function withDescription(?string $description = null) + public function withDescription(?string $description = null): self { $self = clone $this; $self->description = $description; @@ -393,7 +394,10 @@ public function getTypes(): array return $this->types; } - public function withTypes(array $types = []) + /** + * @param string[]|string $types + */ + public function withTypes($types = []): self { $self = clone $this; $self->types = $types; diff --git a/src/Metadata/Patch.php b/src/Metadata/Patch.php index 0e9b7dd5457..ad314c13f71 100644 --- a/src/Metadata/Patch.php +++ b/src/Metadata/Patch.php @@ -14,7 +14,7 @@ namespace ApiPlatform\Metadata; #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)] -class Patch extends Operation +final class Patch extends Operation { /** * {@inheritdoc} @@ -23,7 +23,7 @@ public function __construct( ?string $uriTemplate = null, ?string $shortName = null, ?string $description = null, - array $types = [], + $types = [], $formats = null, $inputFormats = null, $outputFormats = null, diff --git a/src/Metadata/Post.php b/src/Metadata/Post.php index 76ac7b521cf..ff34815fd71 100644 --- a/src/Metadata/Post.php +++ b/src/Metadata/Post.php @@ -14,7 +14,7 @@ namespace ApiPlatform\Metadata; #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)] -class Post extends Operation +final class Post extends Operation { /** * {@inheritdoc} @@ -23,7 +23,7 @@ public function __construct( ?string $uriTemplate = null, ?string $shortName = null, ?string $description = null, - array $types = [], + $types = [], $formats = null, $inputFormats = null, $outputFormats = null, diff --git a/src/Metadata/Put.php b/src/Metadata/Put.php index 9f6556205a6..f93db961f57 100644 --- a/src/Metadata/Put.php +++ b/src/Metadata/Put.php @@ -14,7 +14,7 @@ namespace ApiPlatform\Metadata; #[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)] -class Put extends Operation +final class Put extends Operation { /** * {@inheritdoc} @@ -23,7 +23,7 @@ public function __construct( ?string $uriTemplate = null, ?string $shortName = null, ?string $description = null, - array $types = [], + $types = [], $formats = null, $inputFormats = null, $outputFormats = null,