Skip to content

Commit

Permalink
fix denormalizing float from sql
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptouuuu committed Oct 31, 2024
1 parent f1ebb0a commit 4da4d44
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions fixtures/CreatedAtType.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,13 @@ public function normalize(mixed $value): null|string|int|float|bool

public function denormalize(null|string|int|float|bool $value): mixed
{
if (!\is_float($value) && !\is_int($value)) {
if (!\is_numeric($value)) {
throw new \LogicException("'$value' is not a float");
}

return new CreatedAt($value);
// With SQL the value is read from the database as a string. Adding 0
// allows to convert the string to the correct type (int or float)
// without modifying its value.
return new CreatedAt($value + 0);
}
}

0 comments on commit 4da4d44

Please sign in to comment.