From 56610512da79870028a3e24e721466e1ece2f0b6 Mon Sep 17 00:00:00 2001 From: cizordj <32869222+cizordj@users.noreply.github.com> Date: Sun, 3 Sep 2023 10:37:03 -0300 Subject: [PATCH] Change BigIntType Casting - Cast to int within safe range, else to string. --- src/Types/BigIntType.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Types/BigIntType.php b/src/Types/BigIntType.php index 1d068a42c2d..8489cf641e1 100644 --- a/src/Types/BigIntType.php +++ b/src/Types/BigIntType.php @@ -8,7 +8,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; /** - * Type that maps a database BIGINT to a PHP string. + * Type that maps a database BIGINT to a PHP int. */ class BigIntType extends Type implements PhpIntegerMappingType { @@ -22,18 +22,27 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st public function getBindingType(): ParameterType { - return ParameterType::STRING; + return ParameterType::INTEGER; } /** * @param T $value * - * @return (T is null ? null : string) + * @return (T is null ? null : int|string) * * @template T */ - public function convertToPHPValue(mixed $value, AbstractPlatform $platform): ?string + public function convertToPHPValue(mixed $value, AbstractPlatform $platform): int|string|null { - return $value === null ? null : (string) $value; + if (null === $value) { + return null; + } elseif ( + $value <= PHP_INT_MAX && + $value >= PHP_INT_MIN + ) { + return (int) $value; + } else { + return (string) $value; + } } }