Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
AurelienPillevesse committed Feb 10, 2024
1 parent 344f6f5 commit 1373073
Showing 1 changed file with 4 additions and 4 deletions.
Expand Up @@ -47,17 +47,17 @@ public function normalize(string $propertyName, ?string $class = null, ?string $

public function denormalize(string $propertyName, ?string $class = null, ?string $format = null, array $context = []): string
{
if (($context[self::REQUIRE_SNAKE_CASE_PROPERTIES] ?? false) && $propertyName !== $this->normalize($propertyName, $class, $format, $context)) {
throw new NotNormalizableValueException('Could not denormalize property, snake case format accepted only.');
}

$camelCasedName = preg_replace_callback('/(^|_|\.)+(.)/', fn ($match) => ('.' === $match[1] ? '_' : '').strtoupper($match[2]), $propertyName);

if ($this->lowerCamelCase) {
$camelCasedName = lcfirst($camelCasedName);
}

if (null === $this->attributes || \in_array($camelCasedName, $this->attributes, true)) {
if (($context[self::REQUIRE_SNAKE_CASE_PROPERTIES] ?? false) && $propertyName !== $this->normalize($propertyName, $class, $format, $context)) {
throw new NotNormalizableValueException('Could not denormalize property, snake case format accepted only.');
}

return $camelCasedName;
}

Expand Down

0 comments on commit 1373073

Please sign in to comment.