Skip to content

Commit 031e737

Browse files
authored
fix(metadata): add missing deprecations in ApiProperty (api-platform#4424)
1 parent 3d37a8b commit 031e737

File tree

2 files changed

+46
-21
lines changed

2 files changed

+46
-21
lines changed

src/Metadata/ApiProperty.php

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -105,35 +105,35 @@ final class ApiProperty
105105
private $extraProperties;
106106

107107
/**
108-
* @param string $description
109-
* @param bool $readable
110-
* @param bool $writable
111-
* @param bool $readableLink
112-
* @param bool $writableLink
113-
* @param bool $required
114-
* @param bool $identifier
115-
* @param string|int|float|bool|array $default
116-
* @param string|int|float|bool|array|null $example
117-
* @param string $deprecationReason
118-
* @param bool $fetchable
119-
* @param bool $fetchEager
120-
* @param array $jsonldContext
121-
* @param array $openapiContext
122-
* @param bool $push
123-
* @param string $security
124-
* @param string $securityPostDenormalize
108+
* @param string $description
109+
* @param bool $readable
110+
* @param bool $writable
111+
* @param bool $readableLink
112+
* @param bool $writableLink
113+
* @param bool $required
114+
* @param bool $identifier
115+
* @param string|int|float|bool|array $default
116+
* @param string|int|float|bool|array $example
117+
* @param string $deprecationReason
118+
* @param bool $fetchable
119+
* @param bool $fetchEager
120+
* @param array $jsonldContext
121+
* @param array $openapiContext
122+
* @param bool $push
123+
* @param string $security
124+
* @param string $securityPostDenormalize
125125
*/
126126
public function __construct(
127-
$description = null,
127+
?string $description = null,
128128
?bool $readable = null,
129129
?bool $writable = null,
130130
?bool $readableLink = null,
131131
?bool $writableLink = null,
132132
?bool $required = null,
133133
?bool $identifier = null,
134134

135-
$default = null,
136-
$example = null,
135+
$default = null,
136+
$example = null,
137137

138138
?string $deprecationReason = null,
139139
?bool $fetchable = null,
@@ -469,7 +469,9 @@ public function withExtraProperties(array $extraProperties = []): self
469469
return $self;
470470
}
471471

472-
/** TODO: backward compatibility layer with previous PropertyMetadata to be removed in 3.0 */
472+
/**
473+
* @deprecated since 2.7, to be removed in 3.0
474+
*/
473475
public function withSubresource(SubresourceMetadata $subresourceMetadata): self
474476
{
475477
trigger_deprecation('api-platform/core', '2.7', 'Declaring a subresource on a property is deprecated, use alternate URLs instead.');
@@ -479,13 +481,18 @@ public function withSubresource(SubresourceMetadata $subresourceMetadata): self
479481
return $self;
480482
}
481483

484+
/**
485+
* @deprecated since 2.7, to be removed in 3.0
486+
*/
482487
public function getSubresource(): ?SubresourceMetadata
483488
{
484489
return $this->extraProperties['subresource'] ?? null;
485490
}
486491

487492
/**
488493
* Represents whether the property has a subresource.
494+
*
495+
* @deprecated since 2.7, to be removed in 3.0
489496
*/
490497
public function hasSubresource(): bool
491498
{
@@ -533,6 +540,8 @@ public function withChildInherited(string $childInherited): self
533540

534541
/**
535542
* Gets IRI of this property.
543+
*
544+
* @deprecated since 2.7, to be removed in 3.0, use getTypes instead
536545
*/
537546
public function getIri(): ?string
538547
{
@@ -541,6 +550,8 @@ public function getIri(): ?string
541550

542551
/**
543552
* Returns a new instance with the given IRI.
553+
*
554+
* @deprecated since 2.7, to be removed in 3.0, use withTypes instead
544555
*/
545556
public function withIri(string $iri = null): self
546557
{
@@ -555,6 +566,8 @@ public function withIri(string $iri = null): self
555566
/**
556567
* Gets an attribute.
557568
*
569+
* @deprecated since 2.7, to be removed in 3.0, use getExtraProperties instead
570+
*
558571
* @param mixed|null $defaultValue
559572
*/
560573
public function getAttribute(string $key, $defaultValue = null)
@@ -576,6 +589,8 @@ public function getAttribute(string $key, $defaultValue = null)
576589

577590
/**
578591
* Gets attributes.
592+
*
593+
* @deprecated since 2.7, to be removed in 3.0, renamed as getExtraProperties
579594
*/
580595
public function getAttributes(): ?array
581596
{
@@ -584,9 +599,13 @@ public function getAttributes(): ?array
584599

585600
/**
586601
* Returns a new instance with the given attribute.
602+
*
603+
* @deprecated since 2.7, to be removed in 3.0, renamed as withExtraProperties
587604
*/
588605
public function withAttributes(array $attributes): self
589606
{
607+
trigger_deprecation('api-platform/core', '2.7', sprintf('"%s::%s" is deprecated since 2.7 and will be removed in 3.0.', __CLASS__, __METHOD__));
608+
590609
$metadata = clone $this;
591610

592611
return $this->withDeprecatedAttributes($metadata, $attributes);

src/Metadata/Property/Factory/AttributePropertyMetadataFactory.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,14 @@ private function createMetadata(ApiProperty $attribute, ApiProperty $propertyMet
104104

105105
foreach (get_class_methods(ApiProperty::class) as $method) {
106106
if (
107+
// TODO: remove these checks for deprecated methods in 3.0
107108
'getAttribute' !== $method &&
108109
'isChildInherited' !== $method &&
110+
'getSubresource' !== $method &&
111+
'getIri' !== $method &&
112+
'getAttributes' !== $method &&
113+
// end of deprecated methods
114+
109115
preg_match('/^(?:get|is)(.*)/', $method, $matches) &&
110116
null !== $val = $attribute->{$method}()
111117
) {

0 commit comments

Comments
 (0)