Skip to content

Commit a5383c7

Browse files
minor #41973 Leverage str_ends_with (Tobion)
This PR was merged into the 4.4 branch. Discussion ---------- Leverage str_ends_with | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | | License | MIT | Doc PR | added the php80 polyfill to requirements when necessary. some components already had the requirement anyway. Related to #41576 Commits ------- 9d807298be Leverage str_ends_with
2 parents 0243383 + ffc26d5 commit a5383c7

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)