Skip to content

Commit 1e6d13a

Browse files
authored
feat!: core 5.0 cleanups (getProperties interface, json:api status string) (#8366)
1 parent 8db71f6 commit 1e6d13a

7 files changed

Lines changed: 15 additions & 37 deletions

File tree

src/Doctrine/Common/Filter/PropertyAwareFilterInterface.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@
1414
namespace ApiPlatform\Doctrine\Common\Filter;
1515

1616
/**
17-
* TODO: 5.x uncomment method.
18-
*
1917
* @author Antoine Bluchet <soyuka@gmail.com>
20-
*
21-
* @method array<string>|null getProperties()
2218
*/
2319
interface PropertyAwareFilterInterface
2420
{
@@ -27,8 +23,8 @@ interface PropertyAwareFilterInterface
2723
*/
2824
public function setProperties(array $properties): void;
2925

30-
// /**
31-
// * @return string[]
32-
// */
33-
// public function getProperties(): ?array;
26+
/**
27+
* @return string[]
28+
*/
29+
public function getProperties(): ?array;
3430
}

src/Doctrine/Common/ParameterExtensionTrait.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,7 @@ private function configureFilter(object $filter, Parameter $parameter): void
5151
}
5252

5353
if ($filter instanceof PropertyAwareFilterInterface) {
54-
$properties = [];
55-
// Check if the filter has getProperties method (e.g., if it's an AbstractFilter)
56-
if (method_exists($filter, 'getProperties')) { // @phpstan-ignore-line todo 5.x remove this check @see interface
57-
$properties = $filter->getProperties() ?? [];
58-
}
54+
$properties = $filter->getProperties() ?? [];
5955

6056
$propertyKey = $parameter->getProperty() ?? $parameter->getKey();
6157
foreach ($parameter->getProperties() ?? [$propertyKey] as $property) {

src/JsonApi/Serializer/ErrorNormalizer.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ public function normalize(mixed $data, ?string $format = null, array $context =
4545
$error['code'] = $data->getId();
4646
}
4747

48-
// TODO: change this 5.x
49-
// if (isset($error['status'])) {
50-
// $error['status'] = (string) $error['status'];
51-
// }
48+
if (isset($error['status'])) {
49+
$error['status'] = (string) $error['status'];
50+
}
5251

5352
if (!isset($error['violations'])) {
5453
return ['errors' => [$error]];

src/Laravel/State/ValidateProvider.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,6 @@ private function getBodyForValidation(mixed $body): array
115115
return $v;
116116
}
117117

118-
// hopefully this path never gets used, its there for BC-layer only
119-
// TODO: remove in 5.0
120-
if ($s = json_encode($body)) {
121-
return json_decode($s, true);
122-
}
123-
124118
throw new RuntimeException('Could not transform the denormalized body in an array for validation');
125119
}
126120
}

src/Laravel/Tests/JsonApiTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,13 +250,13 @@ public function testValidateJsonApi(): void
250250
[
251251
'detail' => 'The prop field is required.',
252252
'title' => 'Validation Error',
253-
'status' => 422,
253+
'status' => '422',
254254
'code' => '58350900e0fc6b8e/prop',
255255
],
256256
[
257257
'detail' => 'The max field must be less than 2.',
258258
'title' => 'Validation Error',
259-
'status' => 422,
259+
'status' => '422',
260260
'code' => '58350900e0fc6b8e/max',
261261
],
262262
],
@@ -294,7 +294,7 @@ public function testNotFound(): void
294294
$this->assertJsonContains([
295295
'links' => ['type' => '/errors/404'],
296296
'title' => 'An error occurred',
297-
'status' => 404,
297+
'status' => '404',
298298
'detail' => 'Not Found',
299299
], $response->json()['errors'][0]);
300300
}

src/Metadata/Resource/Factory/ParameterResourceMetadataCollectionFactory.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,7 @@ private function getProperties(string $resourceClass, ?Parameter $parameter = nu
212212
}
213213

214214
if (($filter = $this->getFilterInstance($parameter->getFilter())) && $filter instanceof PropertyAwareFilterInterface) {
215-
if (!method_exists($filter, 'getProperties')) { // todo 5.x remove this check
216-
trigger_deprecation('api-platform/core', 'In API Platform 5.0 "%s" will implement a method named "getProperties"', PropertyAwareFilterInterface::class);
217-
$refl = new \ReflectionClass($filter);
218-
$filterProperties = $refl->hasProperty('properties') ? $refl->getProperty('properties')->getValue($filter) : [];
219-
} else {
220-
$filterProperties = array_keys($filter->getProperties() ?? []);
221-
}
215+
$filterProperties = array_keys($filter->getProperties() ?? []);
222216

223217
foreach ($filterProperties as $prop) {
224218
if (!\in_array($prop, $propertyNames, true)) {

tests/Functional/JsonApi/ErrorTest.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ public function testErrorResourceRendersInJsonApiFormat(): void
4343
$this->assertJsonContains([
4444
'errors' => [
4545
[
46-
// TODO: change this to '400' in 5.x
47-
'status' => 400,
46+
'status' => '400',
4847
'detail' => 'Resource "nonexistent" not found.',
4948
],
5049
],
@@ -91,7 +90,7 @@ public function testRfc7807ErrorRendersJsonApiFormat(): void
9190
$this->assertResponseHeaderSame('content-type', 'application/vnd.api+json; charset=utf-8');
9291
$body = $response->toArray(false);
9392
$this->assertSame('An error occurred', $body['errors'][0]['title']);
94-
$this->assertSame(400, $body['errors'][0]['status']);
93+
$this->assertSame('400', $body['errors'][0]['status']);
9594
$this->assertArrayHasKey('detail', $body['errors'][0]);
9695
$this->assertArrayHasKey('type', $body['errors'][0]);
9796
}
@@ -110,7 +109,7 @@ public function testNotFoundRouteRendersJsonApiFormat(): void
110109
$this->assertResponseHeaderSame('content-type', 'application/vnd.api+json; charset=utf-8');
111110
$body = $response->toArray(false);
112111
$this->assertSame('An error occurred', $body['errors'][0]['title']);
113-
$this->assertSame(404, $body['errors'][0]['status']);
112+
$this->assertSame('404', $body['errors'][0]['status']);
114113
$this->assertArrayHasKey('detail', $body['errors'][0]);
115114
$this->assertArrayHasKey('type', $body['errors'][0]);
116115
}

0 commit comments

Comments
 (0)