Skip to content

Commit 904ca1f

Browse files
authored
use asserts (#93)
1 parent cc4018c commit 904ca1f

5 files changed

Lines changed: 5 additions & 19 deletions

File tree

lib/Cache.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ public static function get(string $key, \Closure $closure, int $expire = null):
9999

100100
public static function set(string $key, mixed $var, int $expire = null): void
101101
{
102-
if (!static::$adapter) {
103-
return;
104-
}
102+
assert(isset(static::$adapter), 'Adapter required to set');
105103

106104
$key = static::get_namespace() . $key;
107105

@@ -110,9 +108,7 @@ public static function set(string $key, mixed $var, int $expire = null): void
110108

111109
public static function delete(string $key): void
112110
{
113-
if (!static::$adapter) {
114-
return;
115-
}
111+
assert(isset(static::$adapter), 'Adapter required to delete');
116112

117113
$key = static::get_namespace() . $key;
118114
static::$adapter->delete($key);

lib/Column.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,6 @@ public static function castIntegerSafely($value): string|int
117117
return $value;
118118
}
119119

120-
// It's just a decimal number
121-
elseif (is_float($value) && floor($value) != $value) {
122-
return (int) $value;
123-
}
124-
125120
// If adding 0 to a string causes a float conversion,
126121
// we have a number over PHP_INT_MAX
127122
elseif (is_string($value) && 1 === bccomp($value, (string) PHP_INT_MAX)) {
@@ -157,8 +152,7 @@ public function cast($value, $connection): mixed
157152
case self::STRING: return (string) $value;
158153
case self::INTEGER: return static::castIntegerSafely($value);
159154
case self::DECIMAL: return (float) $value;
160-
case self::DATETIME:
161-
case self::DATE:
155+
default: // DATETIME, DATE, TIME
162156
if ('' === $value) {
163157
return null;
164158
}
@@ -179,8 +173,6 @@ public function cast($value, $connection): mixed
179173

180174
return $connection->string_to_datetime($value);
181175
}
182-
183-
return $value;
184176
}
185177

186178
/**

lib/Connection.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ public static function instance(string $connection_string_or_connection_name = n
112112
$config = Config::instance();
113113

114114
if (!str_contains($connection_string_or_connection_name ?? '', '://')) {
115-
$connection_string = $connection_string_or_connection_name ?
116-
$config->get_connection($connection_string_or_connection_name) :
115+
$connection_string = $config->get_connection($connection_string_or_connection_name ?? '') ??
117116
$config->get_default_connection_string();
118117
} else {
119118
$connection_string = $connection_string_or_connection_name;

lib/ConnectionManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ConnectionManager extends Singleton
2828
*
2929
* @return Connection
3030
*/
31-
public static function get_connection($name=null)
31+
public static function get_connection(string $name=null)
3232
{
3333
$config = Config::instance();
3434
$name = $name ?? $config->get_default_connection();

test/helpers/AdapterTestCase.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public function testShouldSetAdapterVariables()
4747

4848
public function testNullConnectionStringUsesDefaultConnection()
4949
{
50-
$this->assertNotNull(ActiveRecord\Connection::instance(null));
5150
$this->assertNotNull(ActiveRecord\Connection::instance(''));
5251
$this->assertNotNull(ActiveRecord\Connection::instance());
5352
}

0 commit comments

Comments
 (0)