diff --git a/VERSION b/VERSION index ccb1560..762127f 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.2410.191502 +0.2410.191515 diff --git a/src/Db/DbStatement.php b/src/Db/DbStatement.php index fed3e37..0398c43 100644 --- a/src/Db/DbStatement.php +++ b/src/Db/DbStatement.php @@ -24,7 +24,7 @@ interface DbStatement { * * @param int $ordinal Index of the target parameter. * @param mixed $value Value to assign to the parameter. - * @param int $type Type of the value, if left to DbType::AUTO DbTools::detectType will be used on $value. + * @param int $type Type of the value, if left to DbType::AUTO DbType::detect will be used on $value. * @throws InvalidArgumentException If $ordinal exceeds bounds. */ function addParameter(int $ordinal, mixed $value, int $type = DbType::AUTO): void; @@ -36,7 +36,7 @@ interface DbStatement { * Overwriting lower ordinals than the current cursor should be fine, but your mileage may vary. * * @param mixed $value Value to assign to the parameter. - * @param int $type Type of the value, if left to DbType::AUTO DbTools::detectType will be used on $value. + * @param int $type Type of the value, if left to DbType::AUTO DbType::detect will be used on $value. * @throws RuntimeException If all parameters have already been specified. */ function nextParameter(mixed $value, int $type = DbType::AUTO): void; diff --git a/src/Db/DbTools.php b/src/Db/DbTools.php index 2848aec..7a3c27c 100644 --- a/src/Db/DbTools.php +++ b/src/Db/DbTools.php @@ -11,24 +11,6 @@ use Countable; * Common database actions. */ final class DbTools { - /** - * Detects the DbType of the passed argument. Should be used for DbType::AUTO. - * - * @param mixed $value A value of unknown type. - * @return int DbType of the value passed in the argument. - */ - public static function detectType(mixed $value): int { - if(is_null($value)) - return DbType::NULL; - if(is_float($value)) - return DbType::FLOAT; - if(is_int($value)) - return DbType::INTEGER; - if(is_resource($value)) - return DbType::BLOB; - return DbType::STRING; - } - /** * Constructs a partial query for prepared statements of lists. * diff --git a/src/Db/DbType.php b/src/Db/DbType.php index f1e4b9c..687abc8 100644 --- a/src/Db/DbType.php +++ b/src/Db/DbType.php @@ -1,7 +1,7 @@ assertEquals(DbType::NULL, DbTools::detectType(null)); - $this->assertEquals(DbType::INTEGER, DbTools::detectType(12345)); - $this->assertEquals(DbType::FLOAT, DbTools::detectType(123.45)); - $this->assertEquals(DbType::STRING, DbTools::detectType('This is a string.')); - - $blob = fopen('php://memory', 'r+b'); - if($blob === false) - throw new RuntimeException('failed to fopen a memory stream'); - - fwrite($blob, 'This is a string inside a memory stream.'); - fseek($blob, 0); - - $this->assertEquals(DbType::BLOB, DbTools::detectType($blob)); - } -} diff --git a/tests/DbTypeTest.php b/tests/DbTypeTest.php new file mode 100644 index 0000000..cac3369 --- /dev/null +++ b/tests/DbTypeTest.php @@ -0,0 +1,29 @@ +assertEquals(DbType::NULL, DbType::detect(null)); + $this->assertEquals(DbType::INTEGER, DbType::detect(12345)); + $this->assertEquals(DbType::FLOAT, DbType::detect(123.45)); + $this->assertEquals(DbType::STRING, DbType::detect('This is a string.')); + + $blob = fopen('php://memory', 'r+b'); + if($blob === false) + throw new RuntimeException('failed to fopen a memory stream'); + + fwrite($blob, 'This is a string inside a memory stream.'); + fseek($blob, 0); + + $this->assertEquals(DbType::BLOB, DbType::detect($blob)); + } +}