From 8d7c95378c88c82305ec30bae4222aca26c4b5a2 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Tue, 5 Aug 2025 22:23:35 +0200 Subject: [PATCH] Core/Cleanup * set type declarations in DB Wrapper --- includes/database.class.php | 47 ++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/includes/database.class.php b/includes/database.class.php index e1b2a718..64956c87 100644 --- a/includes/database.class.php +++ b/includes/database.class.php @@ -13,17 +13,16 @@ if (!defined('AOWOW_REVISION')) class DB { - private static $interfaceCache = []; - private static $optionsCache = []; + private static array $interfaceCache = []; + private static array $optionsCache = []; + private static array $logs = []; - private static $logs = []; - - private static function createConnectSyntax(&$options) + private static function createConnectSyntax(array &$options) : string { return 'mysqli://'.$options['user'].':'.$options['pass'].'@'.$options['host'].'/'.$options['db']; } - public static function connect($idx) + public static function connect(int $idx) : void { if (self::isConnected($idx)) { @@ -73,7 +72,7 @@ class DB return false; } - public static function errorHandler($message, $data) + public static function errorHandler(string $message, array $data) : void { if (!error_reporting()) return; @@ -94,7 +93,7 @@ class DB trigger_error($message, $isError ? E_USER_ERROR : E_USER_WARNING); } - public static function profiler($self, $query, $trace) + public static function profiler(mixed $self, string $query, mixed $trace) : void { if ($trace) // actual query self::$logs[] = [str_replace("\n", ' ', $query)]; @@ -105,7 +104,7 @@ class DB } } - public static function getProfiles() + public static function getProfiles() : string { $out = '
';
         foreach (self::$logs as $i => [$l, $t])
@@ -123,61 +122,61 @@ class DB
         return Util::jsEscape($out).'
TimeQuery
'; } - public static function getDB($idx) + public static function getDB(int $idx) : ?\DbSimple_Mysqli { return self::$interfaceCache[$idx]; } - public static function isConnected($idx) + public static function isConnected(int $idx) : bool { return isset(self::$interfaceCache[$idx]) && self::$interfaceCache[$idx]->link; } - public static function isConnectable($idx) + public static function isConnectable(int $idx) : bool { return isset(self::$optionsCache[$idx]); } /** * @static - * @return DbSimple_Mysql + * @return DbSimple_Mysqli */ - public static function Characters($realm) + public static function Characters(int $realmId) : ?\DbSimple_Mysqli { - if (!isset(self::$optionsCache[DB_CHARACTERS.$realm])) - die('Connection info not found for live database of realm #'.$realm.'. Aborted.'); + if (!isset(self::$optionsCache[DB_CHARACTERS.$realmId])) + die('Connection info not found for live database of realm #'.$realmId.'. Aborted.'); - return self::getDB(DB_CHARACTERS.$realm); + return self::getDB(DB_CHARACTERS.$realmId); } /** * @static - * @return DbSimple_Mysql + * @return DbSimple_Mysqli */ - public static function Auth() + public static function Auth() : ?\DbSimple_Mysqli { return self::getDB(DB_AUTH); } /** * @static - * @return DbSimple_Mysql + * @return DbSimple_Mysqli */ - public static function World() + public static function World() : ?\DbSimple_Mysqli { return self::getDB(DB_WORLD); } /** * @static - * @return DbSimple_Mysql + * @return DbSimple_Mysqli */ - public static function Aowow() + public static function Aowow() : ?\DbSimple_Mysqli { return self::getDB(DB_AOWOW); } - public static function load($idx, $config) + public static function load(int $idx, array $config) : void { self::$optionsCache[$idx] = $config; self::connect($idx);