8000 [Serializer] Fix for method named `get()` by mihai-stancu · Pull Request #58226 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Serializer] Fix for method named get() #58226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Serializer] Fix for method named get()
  • Loading branch information
mihai-stancu authored and nicolas-grekas committed Sep 16, 2024
commit a0d6e261e094e82703c77cb4393383f78132f076
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,19 @@ protected function extractAttributes(object $object, ?string $format = null, arr
$name = $reflMethod->name;
$attributeName = null;

if (str_starts_with($name, 'get') || str_starts_with($name, 'has') || str_starts_with($name, 'can')) {
if (3 < \strlen($name) && match ($name[0]) {
'g' => str_starts_with($name, 'get'),
'h' => str_starts_with($name, 'has'),
'c' => str_starts_with($name, 'can'),
default => false,
}) {
// getters, hassers and canners
$attributeName = substr($name, 3);

if (!$reflClass->hasProperty($attributeName)) {
$attributeName = lcfirst($attributeName);
}
} elseif (str_starts_with($name, 'is')) {
} elseif ('is' !== $name && str_starts_with($name, 'is')) {
// issers
$attributeName = substr($name, 2);

Expand Down
Loading
0