From c9c0eef15203c9f944ac9f12350fdc27a641e2c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20Kr=C3=A4mer?= Date: Tue, 27 Feb 2018 12:37:55 +0100 Subject: [PATCH] Improving exception msgs for database types --- src/Database/Type/BoolType.php | 5 ++++- src/Database/Type/DecimalType.php | 5 ++++- src/Database/Type/IntegerType.php | 5 ++++- src/Database/Type/StringType.php | 5 ++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Database/Type/BoolType.php b/src/Database/Type/BoolType.php index 7037d25966f..ae54e694aaa 100644 --- a/src/Database/Type/BoolType.php +++ b/src/Database/Type/BoolType.php @@ -67,7 +67,10 @@ public function toDatabase($value, Driver $driver) return (bool)$value; } - throw new InvalidArgumentException('Cannot convert value to bool'); + throw new InvalidArgumentException(sprintf( + 'Cannot convert value of type `%s` to bool', + getTypeName($value) + )); } /** diff --git a/src/Database/Type/DecimalType.php b/src/Database/Type/DecimalType.php index a15e90a4cc8..4040d06a543 100644 --- a/src/Database/Type/DecimalType.php +++ b/src/Database/Type/DecimalType.php @@ -80,7 +80,10 @@ public function toDatabase($value, Driver $driver) return null; } if (!is_scalar($value)) { - throw new InvalidArgumentException('Cannot convert value to a decimal.'); + throw new InvalidArgumentException(sprintf( + 'Cannot convert value of type `%s` to a decimal', + getTypeName($value) + )); } if (is_string($value) && is_numeric($value)) { return $value; diff --git a/src/Database/Type/IntegerType.php b/src/Database/Type/IntegerType.php index eba5ae26326..d2ead25b22c 100644 --- a/src/Database/Type/IntegerType.php +++ b/src/Database/Type/IntegerType.php @@ -64,7 +64,10 @@ public function toDatabase($value, Driver $driver) } if (!is_scalar($value)) { - throw new InvalidArgumentException('Cannot convert value to integer'); + throw new InvalidArgumentException(sprintf( + 'Cannot convert value of type `%s` to integer', + getTypeName($value) + )); } return (int)$value; diff --git a/src/Database/Type/StringType.php b/src/Database/Type/StringType.php index 06b7c8d9a27..d5b01503334 100644 --- a/src/Database/Type/StringType.php +++ b/src/Database/Type/StringType.php @@ -49,7 +49,10 @@ public function toDatabase($value, Driver $driver) return (string)$value; } - throw new InvalidArgumentException('Cannot convert value to string'); + throw new InvalidArgumentException(sprintf( + 'Cannot convert value of type `%s` to string', + getTypeName($value) + )); } /**