Skip to content

Commit

Permalink
minor #41973 Leverage str_ends_with (Tobion)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nicolas-grekas committed Jul 21, 2021
2 parents 0243383 + ffc26d5 commit a5383c7
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Normalizer/ArrayDenormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function denormalize($data, $type, $format = null, array $context = [])
if (!\is_array($data)) {
throw new InvalidArgumentException('Data expected to be an array, '.\gettype($data).' given.');
}
if ('[]' !== substr($type, -2)) {
if (!str_ends_with($type, '[]')) {
throw new InvalidArgumentException('Unsupported class: '.$type);
}

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

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

Expand Down
2 changes: 1 addition & 1 deletion Tests/Normalizer/AbstractObjectNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ public function denormalize($data, $type, $format = null, array $context = [])
*/
public function supportsDenormalization($data, $type, $format = null, array $context = []): bool
{
return '[]' === substr($type, -2)
return str_ends_with($type, '[]')
&& $this->serializer->supportsDenormalization($data, substr($type, 0, -2), $format, $context);
}

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
],
"require": {
"php": ">=7.1.3",
"symfony/polyfill-ctype": "~1.8"
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-php80": "^1.16"
},
"require-dev": {
"doctrine/annotations": "^1.10.4",
Expand Down

0 comments on commit a5383c7

Please sign in to comment.