Skip to content

Commit 67bd7d8

Browse files
authored
fix: improve some types in the new attributes (api-platform#4417)
1 parent a802c85 commit 67bd7d8

File tree

9 files changed

+84
-76
lines changed

9 files changed

+84
-76
lines changed

src/Metadata/ApiProperty.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public function withExample($example): self
294294
return $self;
295295
}
296296

297-
public function getDeprecationReason()
297+
public function getDeprecationReason(): ?string
298298
{
299299
return $this->deprecationReason;
300300
}
@@ -307,7 +307,7 @@ public function withDeprecationReason($deprecationReason): self
307307
return $self;
308308
}
309309

310-
public function isFetchable()
310+
public function isFetchable(): ?bool
311311
{
312312
return $this->fetchable;
313313
}
@@ -320,7 +320,7 @@ public function withFetchable($fetchable): self
320320
return $self;
321321
}
322322

323-
public function getFetchEager()
323+
public function getFetchEager(): ?bool
324324
{
325325
return $this->fetchEager;
326326
}
@@ -333,7 +333,7 @@ public function withFetchEager($fetchEager): self
333333
return $self;
334334
}
335335

336-
public function getJsonldContext()
336+
public function getJsonldContext(): ?array
337337
{
338338
return $this->jsonldContext;
339339
}
@@ -346,7 +346,7 @@ public function withJsonldContext($jsonldContext): self
346346
return $self;
347347
}
348348

349-
public function getOpenapiContext()
349+
public function getOpenapiContext(): ?array
350350
{
351351
return $this->openapiContext;
352352
}
@@ -359,7 +359,7 @@ public function withOpenapiContext($openapiContext): self
359359
return $self;
360360
}
361361

362-
public function getPush()
362+
public function getPush(): ?bool
363363
{
364364
return $this->push;
365365
}
@@ -372,7 +372,7 @@ public function withPush($push): self
372372
return $self;
373373
}
374374

375-
public function getSecurity()
375+
public function getSecurity(): ?string
376376
{
377377
return $this->security;
378378
}
@@ -385,7 +385,7 @@ public function withSecurity($security): self
385385
return $self;
386386
}
387387

388-
public function getSecurityPostDenormalize()
388+
public function getSecurityPostDenormalize(): ?string
389389
{
390390
return $this->securityPostDenormalize;
391391
}

src/Metadata/ApiResource.php

Lines changed: 56 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* @experimental
2121
*/
2222
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
23-
class ApiResource
23+
final class ApiResource
2424
{
2525
private $operations;
2626
private $uriTemplate;
@@ -110,56 +110,57 @@ class ApiResource
110110
private $extraProperties;
111111

112112
/**
113-
* @param string $uriTemplate
114-
* @param string $shortName
115-
* @param string $description
116-
* @param array|string $formats https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation
117-
* @param array|string $inputFormats https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation
118-
* @param array|string $outputFormats https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation
119-
* @param string $routePrefix https://api-platform.com/docs/core/operations/#prefixing-all-routes-of-all-operations
120-
* @param bool $stateless
121-
* @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
122-
* @param string $acceptPatch
123-
* @param string $status
124-
* @param string $class
125-
* @param int $urlGenerationStrategy
126-
* @param string $deprecationReason https://api-platform.com/docs/core/deprecations/#deprecating-resource-classes-operations-and-properties
127-
* @param array $cacheHeaders https://api-platform.com/docs/core/performance/#setting-custom-http-cache-headers
128-
* @param array $normalizationContext https://api-platform.com/docs/core/serialization/#using-serialization-groups
129-
* @param array $denormalizationContext https://api-platform.com/docs/core/serialization/#using-serialization-groups
130-
* @param string[] $hydraContext https://api-platform.com/docs/core/extending-jsonld-context/#hydra
131-
* @param array $openapiContext https://api-platform.com/docs/core/openapi/#using-the-openapi-and-swagger-contexts
132-
* @param array $validationContext https://api-platform.com/docs/core/validation/#using-validation-groups
133-
* @param string[] $filters https://api-platform.com/docs/core/filters/#doctrine-orm-and-mongodb-odm-filters
134-
* @param bool $elasticsearch https://api-platform.com/docs/core/elasticsearch/
135-
* @param bool|array $mercure https://api-platform.com/docs/core/mercure
136-
* @param bool $messenger https://api-platform.com/docs/core/messenger/#dispatching-a-resource-through-the-message-bus
137-
* @param mixed $input https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation
138-
* @param mixed $output https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation
139-
* @param array $order https://api-platform.com/docs/core/default-order/#overriding-default-order
140-
* @param bool $fetchPartial https://api-platform.com/docs/core/performance/#fetch-partial
141-
* @param bool $forceEager https://api-platform.com/docs/core/performance/#force-eager
142-
* @param bool $paginationClientEnabled https://api-platform.com/docs/core/pagination/#for-a-specific-resource-1
143-
* @param bool $paginationClientItemsPerPage https://api-platform.com/docs/core/pagination/#for-a-specific-resource-3
144-
* @param bool $paginationClientPartial https://api-platform.com/docs/core/pagination/#for-a-specific-resource-6
145-
* @param array $paginationViaCursor https://api-platform.com/docs/core/pagination/#cursor-based-pagination
146-
* @param bool $paginationEnabled https://api-platform.com/docs/core/pagination/#for-a-specific-resource
147-
* @param bool $paginationFetchJoinCollection https://api-platform.com/docs/core/pagination/#controlling-the-behavior-of-the-doctrine-orm-paginator
148-
* @param int $paginationItemsPerPage https://api-platform.com/docs/core/pagination/#changing-the-number-of-items-per-page
149-
* @param int $paginationMaximumItemsPerPage https://api-platform.com/docs/core/pagination/#changing-maximum-items-per-page
150-
* @param bool $paginationPartial https://api-platform.com/docs/core/performance/#partial-pagination
151-
* @param string $paginationType https://api-platform.com/docs/core/graphql/#using-the-page-based-pagination
152-
* @param string $security https://api-platform.com/docs/core/security
153-
* @param string $securityMessage https://api-platform.com/docs/core/security/#configuring-the-access-control-error-message
154-
* @param string $securityPostDenormalize https://api-platform.com/docs/core/security/#executing-access-control-rules-after-denormalization
155-
* @param string $securityPostDenormalizeMessage https://api-platform.com/docs/core/security/#configuring-the-access-control-error-message
156-
* @param bool $compositeIdentifier
113+
* @param string $uriTemplate
114+
* @param string $shortName
115+
* @param string $description
116+
* @param string[]|string $types
117+
* @param array|string $formats https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation
118+
* @param array|string $inputFormats https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation
119+
* @param array|string $outputFormats https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation
120+
* @param string $routePrefix https://api-platform.com/docs/core/operations/#prefixing-all-routes-of-all-operations
121+
* @param bool $stateless
122+
* @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
123+
* @param string $acceptPatch
124+
* @param string $status
125+
* @param string $class
126+
* @param int $urlGenerationStrategy
127+
* @param string $deprecationReason https://api-platform.com/docs/core/deprecations/#deprecating-resource-classes-operations-and-properties
128+
* @param array $cacheHeaders https://api-platform.com/docs/core/performance/#setting-custom-http-cache-headers
129+
* @param array $normalizationContext https://api-platform.com/docs/core/serialization/#using-serialization-groups
130+
* @param array $denormalizationContext https://api-platform.com/docs/core/serialization/#using-serialization-groups
131+
* @param string[] $hydraContext https://api-platform.com/docs/core/extending-jsonld-context/#hydra
132+
* @param array $openapiContext https://api-platform.com/docs/core/openapi/#using-the-openapi-and-swagger-contexts
133+
* @param array $validationContext https://api-platform.com/docs/core/validation/#using-validation-groups
134+
* @param string[] $filters https://api-platform.com/docs/core/filters/#doctrine-orm-and-mongodb-odm-filters
135+
* @param bool $elasticsearch https://api-platform.com/docs/core/elasticsearch/
136+
* @param bool|array $mercure https://api-platform.com/docs/core/mercure
137+
* @param bool $messenger https://api-platform.com/docs/core/messenger/#dispatching-a-resource-through-the-message-bus
138+
* @param mixed $input https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation
139+
* @param mixed $output https://api-platform.com/docs/core/dto/#specifying-an-input-or-an-output-data-representation
140+
* @param array $order https://api-platform.com/docs/core/default-order/#overriding-default-order
141+
* @param bool $fetchPartial https://api-platform.com/docs/core/performance/#fetch-partial
142+
* @param bool $forceEager https://api-platform.com/docs/core/performance/#force-eager
143+
* @param bool $paginationClientEnabled https://api-platform.com/docs/core/pagination/#for-a-specific-resource-1
144+
* @param bool $paginationClientItemsPerPage https://api-platform.com/docs/core/pagination/#for-a-specific-resource-3
145+
* @param bool $paginationClientPartial https://api-platform.com/docs/core/pagination/#for-a-specific-resource-6
146+
* @param array $paginationViaCursor https://api-platform.com/docs/core/pagination/#cursor-based-pagination
147+
* @param bool $paginationEnabled https://api-platform.com/docs/core/pagination/#for-a-specific-resource
148+
* @param bool $paginationFetchJoinCollection https://api-platform.com/docs/core/pagination/#controlling-the-behavior-of-the-doctrine-orm-paginator
149+
* @param int $paginationItemsPerPage https://api-platform.com/docs/core/pagination/#changing-the-number-of-items-per-page
150+
* @param int $paginationMaximumItemsPerPage https://api-platform.com/docs/core/pagination/#changing-maximum-items-per-page
151+
* @param bool $paginationPartial https://api-platform.com/docs/core/performance/#partial-pagination
152+
* @param string $paginationType https://api-platform.com/docs/core/graphql/#using-the-page-based-pagination
153+
* @param string $security https://api-platform.com/docs/core/security
154+
* @param string $securityMessage https://api-platform.com/docs/core/security/#configuring-the-access-control-error-message
155+
* @param string $securityPostDenormalize https://api-platform.com/docs/core/security/#executing-access-control-rules-after-denormalization
156+
* @param string $securityPostDenormalizeMessage https://api-platform.com/docs/core/security/#configuring-the-access-control-error-message
157+
* @param bool $compositeIdentifier
157158
*/
158159
public function __construct(
159160
?string $uriTemplate = null,
160161
?string $shortName = null,
161162
?string $description = null,
162-
array $types = [],
163+
$types = [],
163164
$operations = [],
164165
$formats = null,
165166
$inputFormats = null,
@@ -220,7 +221,7 @@ public function __construct(
220221
$this->uriTemplate = $uriTemplate;
221222
$this->shortName = $shortName;
222223
$this->description = $description;
223-
$this->types = $types;
224+
$this->types = (array) $types;
224225
$this->formats = $formats;
225226
$this->inputFormats = $inputFormats;
226227
$this->outputFormats = $outputFormats;
@@ -295,7 +296,7 @@ public function getUriTemplate(): ?string
295296
return $this->uriTemplate;
296297
}
297298

298-
public function withUriTemplate(?string $uriTemplate = null)
299+
public function withUriTemplate(?string $uriTemplate = null): self
299300
{
300301
$self = clone $this;
301302
$self->uriTemplate = $uriTemplate;
@@ -308,7 +309,7 @@ public function getShortName(): ?string
308309
return $this->shortName;
309310
}
310311

311-
public function withShortName(?string $shortName = null)
312+
public function withShortName(?string $shortName = null): self
312313
{
313314
$self = clone $this;
314315
$self->shortName = $shortName;
@@ -321,7 +322,7 @@ public function getDescription(): ?string
321322
return $this->description;
322323
}
323324

324-
public function withDescription(?string $description = null)
325+
public function withDescription(?string $description = null): self
325326
{
326327
$self = clone $this;
327328
$self->description = $description;
@@ -334,10 +335,13 @@ public function getTypes(): array
334335
return $this->types;
335336
}
336337

337-
public function withTypes(array $types = [])
338+
/**
339+
* @param string[]|string $types
340+
*/
341+
public function withTypes($types = []): self
338342
{
339343
$self = clone $this;
340-
$self->types = $types;
344+
$self->types = (array) $types;
341345

342346
return $self;
343347
}

src/Metadata/Delete.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace ApiPlatform\Metadata;
1515

1616
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
17-
class Delete extends Operation
17+
final class Delete extends Operation
1818
{
1919
/**
2020
* {@inheritdoc}
@@ -24,7 +24,7 @@ public function __construct(
2424
?string $uriTemplate = null,
2525
?string $shortName = null,
2626
?string $description = null,
27-
array $types = [],
27+
$types = [],
2828
$formats = null,
2929
$inputFormats = null,
3030
$outputFormats = null,

src/Metadata/Get.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function __construct(
2323
?string $uriTemplate = null,
2424
?string $shortName = null,
2525
?string $description = null,
26-
array $types = [],
26+
$types = [],
2727
$formats = null,
2828
$inputFormats = null,
2929
$outputFormats = null,

src/Metadata/GetCollection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace ApiPlatform\Metadata;
1515

1616
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
17-
class GetCollection extends Operation
17+
final class GetCollection extends Operation
1818
{
1919
/**
2020
* {@inheritdoc}
@@ -23,7 +23,7 @@ public function __construct(
2323
?string $uriTemplate = null,
2424
?string $shortName = null,
2525
?string $description = null,
26-
array $types = [],
26+
$types = [],
2727
$formats = null,
2828
$inputFormats = null,
2929
$outputFormats = null,

src/Metadata/Operation.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class Operation
125125
* @param string $uriTemplate
126126
* @param string $shortName
127127
* @param string $description
128+
* @param string[]|string $types
128129
* @param array|string $formats https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation
129130
* @param array|string $inputFormats https://api-platform.com/docs/core/content-negotiation/#configuring-formats-for-a-specific-resource-or-operation
130131
* @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(
180181
?string $uriTemplate = null,
181182
?string $shortName = null,
182183
?string $description = null,
183-
array $types = [],
184+
$types = [],
184185
$formats = null,
185186
$inputFormats = null,
186187
$outputFormats = null,
@@ -251,7 +252,7 @@ public function __construct(
251252
$this->uriTemplate = $uriTemplate;
252253
$this->shortName = $shortName;
253254
$this->description = $description;
254-
$this->types = $types;
255+
$this->types = (array) $types;
255256
$this->formats = $formats;
256257
$this->inputFormats = $inputFormats;
257258
$this->outputFormats = $outputFormats;
@@ -367,7 +368,7 @@ public function getShortName(): ?string
367368
return $this->shortName;
368369
}
369370

370-
public function withShortName(?string $shortName = null)
371+
public function withShortName(?string $shortName = null): self
371372
{
372373
$self = clone $this;
373374
$self->shortName = $shortName;
@@ -380,7 +381,7 @@ public function getDescription(): ?string
380381
return $this->description;
381382
}
382383

383-
public function withDescription(?string $description = null)
384+
public function withDescription(?string $description = null): self
384385
{
385386
$self = clone $this;
386387
$self->description = $description;
@@ -393,7 +394,10 @@ public function getTypes(): array
393394
return $this->types;
394395
}
395396

396-
public function withTypes(array $types = [])
397+
/**
398+
* @param string[]|string $types
399+
*/
400+
public function withTypes($types = []): self
397401
{
398402
$self = clone $this;
399403
$self->types = $types;

src/Metadata/Patch.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace ApiPlatform\Metadata;
1515

1616
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
17-
class Patch extends Operation
17+
final class Patch extends Operation
1818
{
1919
/**
2020
* {@inheritdoc}
@@ -23,7 +23,7 @@ public function __construct(
2323
?string $uriTemplate = null,
2424
?string $shortName = null,
2525
?string $description = null,
26-
array $types = [],
26+
$types = [],
2727
$formats = null,
2828
$inputFormats = null,
2929
$outputFormats = null,

src/Metadata/Post.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace ApiPlatform\Metadata;
1515

1616
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
17-
class Post extends Operation
17+
final class Post extends Operation
1818
{
1919
/**
2020
* {@inheritdoc}
@@ -23,7 +23,7 @@ public function __construct(
2323
?string $uriTemplate = null,
2424
?string $shortName = null,
2525
?string $description = null,
26-
array $types = [],
26+
$types = [],
2727
$formats = null,
2828
$inputFormats = null,
2929
$outputFormats = null,

src/Metadata/Put.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
namespace ApiPlatform\Metadata;
1515

1616
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
17-
class Put extends Operation
17+
final class Put extends Operation
1818
{
1919
/**
2020
* {@inheritdoc}
@@ -23,7 +23,7 @@ public function __construct(
2323
?string $uriTemplate = null,
2424
?string $shortName = null,
2525
?string $description = null,
26-
array $types = [],
26+
$types = [],
2727
$formats = null,
2828
$inputFormats = null,
2929
$outputFormats = null,

0 commit comments

Comments
 (0)