Skip to content

Commit ffc26d5

Browse files
committed
Leverage str_ends_with
added the php80 polyfill to requirements when necessary
1 parent c7b7bb8 commit ffc26d5

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

Normalizer/ArrayDenormalizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function denormalize($data, $type, $format = null, array $context = [])
4646
if (!\is_array($data)) {
4747
throw new InvalidArgumentException('Data expected to be an array, '.\gettype($data).' given.');
4848
}
49-
if ('[]' !== substr($type, -2)) {
49+
if (!str_ends_with($type, '[]')) {
5050
throw new InvalidArgumentException('Unsupported class: '.$type);
5151
}
5252

@@ -74,7 +74,7 @@ public function supportsDenormalization($data, $type, $format = null, array $con
7474
throw new BadMethodCallException(sprintf('The serializer needs to be set to allow "%s()" to be used.', __METHOD__));
7575
}
7676

77-
return '[]' === substr($type, -2)
77+
return str_ends_with($type, '[]')
7878
&& $this->serializer->supportsDenormalization($data, substr($type, 0, -2), $format, $context);
7979
}
8080

Tests/Normalizer/AbstractObjectNormalizerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ public function denormalize($data, $type, $format = null, array $context = [])
484484
*/
485485
public function supportsDenormalization($data, $type, $format = null, array $context = []): bool
486486
{
487-
return '[]' === substr($type, -2)
487+
return str_ends_with($type, '[]')
488488
&& $this->serializer->supportsDenormalization($data, substr($type, 0, -2), $format, $context);
489489
}
490490

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
],
1818
"require": {
1919
"php": ">=7.1.3",
20-
"symfony/polyfill-ctype": "~1.8"
20+
"symfony/polyfill-ctype": "~1.8",
21+
"symfony/polyfill-php80": "^1.16"
2122
},
2223
"require-dev": {
2324
"doctrine/annotations": "^1.10.4",

0 commit comments

Comments
 (0)