diff --git a/lib/Cache.php b/lib/Cache.php index 832ef33e..0336fbea 100644 --- a/lib/Cache.php +++ b/lib/Cache.php @@ -99,9 +99,7 @@ public static function get(string $key, \Closure $closure, int $expire = null): public static function set(string $key, mixed $var, int $expire = null): void { - if (!static::$adapter) { - return; - } + assert(isset(static::$adapter), 'Adapter required to set'); $key = static::get_namespace() . $key; @@ -110,9 +108,7 @@ public static function set(string $key, mixed $var, int $expire = null): void public static function delete(string $key): void { - if (!static::$adapter) { - return; - } + assert(isset(static::$adapter), 'Adapter required to delete'); $key = static::get_namespace() . $key; static::$adapter->delete($key); diff --git a/lib/Column.php b/lib/Column.php index 467abff9..a923017b 100644 --- a/lib/Column.php +++ b/lib/Column.php @@ -117,11 +117,6 @@ public static function castIntegerSafely($value): string|int return $value; } - // It's just a decimal number - elseif (is_float($value) && floor($value) != $value) { - return (int) $value; - } - // If adding 0 to a string causes a float conversion, // we have a number over PHP_INT_MAX elseif (is_string($value) && 1 === bccomp($value, (string) PHP_INT_MAX)) { @@ -157,8 +152,7 @@ public function cast($value, $connection): mixed case self::STRING: return (string) $value; case self::INTEGER: return static::castIntegerSafely($value); case self::DECIMAL: return (float) $value; - case self::DATETIME: - case self::DATE: + default: // DATETIME, DATE, TIME if ('' === $value) { return null; } @@ -179,8 +173,6 @@ public function cast($value, $connection): mixed return $connection->string_to_datetime($value); } - - return $value; } /** diff --git a/lib/Connection.php b/lib/Connection.php index 3b2ed244..19014de5 100644 --- a/lib/Connection.php +++ b/lib/Connection.php @@ -112,8 +112,7 @@ public static function instance(string $connection_string_or_connection_name = n $config = Config::instance(); if (!str_contains($connection_string_or_connection_name ?? '', '://')) { - $connection_string = $connection_string_or_connection_name ? - $config->get_connection($connection_string_or_connection_name) : + $connection_string = $config->get_connection($connection_string_or_connection_name ?? '') ?? $config->get_default_connection_string(); } else { $connection_string = $connection_string_or_connection_name; diff --git a/lib/ConnectionManager.php b/lib/ConnectionManager.php index bc205ed1..f5c4cd25 100644 --- a/lib/ConnectionManager.php +++ b/lib/ConnectionManager.php @@ -28,7 +28,7 @@ class ConnectionManager extends Singleton * * @return Connection */ - public static function get_connection($name=null) + public static function get_connection(string $name=null) { $config = Config::instance(); $name = $name ?? $config->get_default_connection(); diff --git a/test/helpers/AdapterTestCase.php b/test/helpers/AdapterTestCase.php index dfb2ed37..b9b3bd51 100644 --- a/test/helpers/AdapterTestCase.php +++ b/test/helpers/AdapterTestCase.php @@ -47,7 +47,6 @@ public function testShouldSetAdapterVariables() public function testNullConnectionStringUsesDefaultConnection() { - $this->assertNotNull(ActiveRecord\Connection::instance(null)); $this->assertNotNull(ActiveRecord\Connection::instance('')); $this->assertNotNull(ActiveRecord\Connection::instance()); }