Skip to content

[Serializer] Re-add AdvancedNameConverterInterface #58307

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

Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @author Kévin Dunglas <dunglas@gmail.com>
* @author Aurélien Pillevesse <aurelienpillevesse@hotmail.fr>
*/
class CamelCaseToSnakeCaseNameConverter implements NameConverterInterface
class CamelCaseToSnakeCaseNameConverter implements NameConverterInterface, AdvancedNameConverterInterface
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CamelCaseToSnakeCaseNameConverter was not an advanced converter in 7.0 so there is nothing to re-add there, and adding the arguments in the signature natively is a BC break for child classes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, you're right, plus I didn't get all the history of that PR (#53898 (comment)).

I'm going to close that PR, thanks!

{
/**
* Require all properties to be written in snake_case.
Expand All @@ -41,7 +41,7 @@
* @param string|null $format
* @param array<string, mixed> $context
*/
public function normalize(string $propertyName/* , ?string $class = null, ?string $format = null, array $context = [] */): string
public function normalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string

Check failure on line 44 in src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php

View workflow job for this annotation

GitHub Actions / Psalm

MoreSpecificImplementedParamType

src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php:44:61: MoreSpecificImplementedParamType: Argument 2 of Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter::normalize has the more specific type 'class-string|null', expecting 'null|string' as defined by Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface::normalize (see https://psalm.dev/140)

Check failure on line 44 in src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php

View workflow job for this annotation

GitHub Actions / Psalm

MoreSpecificImplementedParamType

src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php:44:106: MoreSpecificImplementedParamType: Argument 4 of Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter::normalize has the more specific type 'array<string, mixed>', expecting 'array<array-key, mixed>' as defined by Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface::normalize (see https://psalm.dev/140)

Check failure on line 44 in src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php

View workflow job for this annotation

GitHub Actions / Psalm

MoreSpecificImplementedParamType

src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php:44:61: MoreSpecificImplementedParamType: Argument 2 of Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter::normalize has the more specific type 'class-string|null', expecting 'null|string' as defined by Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface::normalize (see https://psalm.dev/140)

Check failure on line 44 in src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php

View workflow job for this annotation

GitHub Actions / Psalm

MoreSpecificImplementedParamType

src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php:44:106: MoreSpecificImplementedParamType: Argument 4 of Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter::normalize has the more specific type 'array<string, mixed>', expecting 'array<array-key, mixed>' as defined by Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface::normalize (see https://psalm.dev/140)
{
if (null === $this->attributes || \in_array($propertyName, $this->attributes, true)) {
return strtolower(preg_replace('/[A-Z]/', '_\\0', lcfirst($propertyName)));
Expand All @@ -55,12 +55,8 @@
* @param string|null $format
* @param array<string, mixed> $context
*/
public function denormalize(string $propertyName/* , ?string $class = null, ?string $format = null, array $context = [] */): string
public function denormalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string

Check failure on line 58 in src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php

View workflow job for this annotation

GitHub Actions / Psalm

MoreSpecificImplementedParamType

src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php:58:63: MoreSpecificImplementedParamType: Argument 2 of Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter::denormalize has the more specific type 'class-string|null', expecting 'null|string' as defined by Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface::denormalize (see https://psalm.dev/140)

Check failure on line 58 in src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php

View workflow job for this annotation

GitHub Actions / Psalm

MoreSpecificImplementedParamType

src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php:58:108: MoreSpecificImplementedParamType: Argument 4 of Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter::denormalize has the more specific type 'array<string, mixed>', expecting 'array<array-key, mixed>' as defined by Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface::denormalize (see https://psalm.dev/140)

Check failure on line 58 in src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php

View workflow job for this annotation

GitHub Actions / Psalm

MoreSpecificImplementedParamType

src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php:58:63: MoreSpecificImplementedParamType: Argument 2 of Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter::denormalize has the more specific type 'class-string|null', expecting 'null|string' as defined by Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface::denormalize (see https://psalm.dev/140)

Check failure on line 58 in src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php

View workflow job for this annotation

GitHub Actions / Psalm

MoreSpecificImplementedParamType

src/Symfony/Component/Serializer/NameConverter/CamelCaseToSnakeCaseNameConverter.php:58:108: MoreSpecificImplementedParamType: Argument 4 of Symfony\Component\Serializer\NameConverter\CamelCaseToSnakeCaseNameConverter::denormalize has the more specific type 'array<string, mixed>', expecting 'array<array-key, mixed>' as defined by Symfony\Component\Serializer\NameConverter\AdvancedNameConverterInterface::denormalize (see https://psalm.dev/140)
{
$class = 1 < \func_num_args() ? func_get_arg(1) : null;
$format = 2 < \func_num_args() ? func_get_arg(2) : null;
$context = 3 < \func_num_args() ? func_get_arg(3) : [];

if (($context[self::REQUIRE_SNAKE_CASE_PROPERTIES] ?? false) && $propertyName !== $this->normalize($propertyName, $class, $format, $context)) {
throw new UnexpectedPropertyException($propertyName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
/**
* @author Fabien Bourigault <bourigaultfabien@gmail.com>
*/
final class MetadataAwareNameConverter implements NameConverterInterface
final class MetadataAwareNameConverter implements NameConverterInterface, AdvancedNameConverterInterface
{
/**
* @var array<string, array<string, string|null>>
Expand Down
Loading