From cb0a28b0bf72891c0c9194c698bbfa1455e30d85 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Mon, 6 May 2024 14:53:34 +0700 Subject: [PATCH] Improve bigint typecasting --- src/Schema/Column/BigIntColumnSchema.php | 26 ++++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Schema/Column/BigIntColumnSchema.php b/src/Schema/Column/BigIntColumnSchema.php index e8f707a5d..2dc2c341b 100644 --- a/src/Schema/Column/BigIntColumnSchema.php +++ b/src/Schema/Column/BigIntColumnSchema.php @@ -7,8 +7,6 @@ use Yiisoft\Db\Expression\ExpressionInterface; use Yiisoft\Db\Schema\SchemaInterface; -use function is_int; - use const PHP_INT_MAX; use const PHP_INT_MIN; @@ -23,18 +21,20 @@ public function __construct( public function dbTypecast(mixed $value): int|string|ExpressionInterface|null { - if (is_int($value)) { - return $value; - } - - return match ($value) { - null, '' => null, - false => 0, - default => $value instanceof ExpressionInterface - ? $value - : (($val = (string) $value) <= PHP_INT_MAX && $val >= PHP_INT_MIN + return match (gettype($value)) { + 'string' => $value === '' ? null : ( + $value <= PHP_INT_MAX && $value >= PHP_INT_MIN + ? (int) $value + : $value + ), + 'NULL' => null, + 'integer' => $value, + 'boolean' => $value ? 1 : 0, + default => $value instanceof ExpressionInterface ? $value : ( + ($val = (string) $value) <= PHP_INT_MAX && $val >= PHP_INT_MIN ? (int) $val - : $val), + : $val + ), }; }