Address PHPStan warnings in 'classes/debug.php'.

This commit is contained in:
wn_ 2021-11-11 21:02:06 +00:00
parent 00b86bac39
commit 58ea0d4339
1 changed files with 32 additions and 17 deletions

View File

@ -6,47 +6,60 @@ class Debug {
const LOG_EXTENDED = 2; const LOG_EXTENDED = 2;
/** @deprecated */ /** @deprecated */
public static $LOG_DISABLED = self::LOG_DISABLED; public static int $LOG_DISABLED = self::LOG_DISABLED;
/** @deprecated */ /** @deprecated */
public static $LOG_NORMAL = self::LOG_NORMAL; public static int $LOG_NORMAL = self::LOG_NORMAL;
/** @deprecated */ /** @deprecated */
public static $LOG_VERBOSE = self::LOG_VERBOSE; public static int $LOG_VERBOSE = self::LOG_VERBOSE;
/** @deprecated */ /** @deprecated */
public static $LOG_EXTENDED = self::LOG_EXTENDED; public static int $LOG_EXTENDED = self::LOG_EXTENDED;
private static $enabled = false; private static bool $enabled = false;
private static $quiet = false; private static bool $quiet = false;
private static $logfile = false; private static ?string $logfile = null;
private static $loglevel = self::LOG_NORMAL;
public static function set_logfile($logfile) { /**
* @var Debug::LOG_*
*/
private static int $loglevel = self::LOG_NORMAL;
public static function set_logfile(string $logfile): void {
self::$logfile = $logfile; self::$logfile = $logfile;
} }
public static function enabled() { public static function enabled(): bool {
return self::$enabled; return self::$enabled;
} }
public static function set_enabled($enable) { public static function set_enabled(bool $enable): void {
self::$enabled = $enable; self::$enabled = $enable;
} }
public static function set_quiet($quiet) { public static function set_quiet(bool $quiet): void {
self::$quiet = $quiet; self::$quiet = $quiet;
} }
public static function set_loglevel($level) { /**
* @param Debug::LOG_* $level
*/
public static function set_loglevel($level): void {
self::$loglevel = $level; self::$loglevel = $level;
} }
public static function get_loglevel() { /**
* @return Debug::LOG_*
*/
public static function get_loglevel(): int {
return self::$loglevel; return self::$loglevel;
} }
public static function log($message, int $level = 0) { /**
* @param Debug::LOG_* $level
*/
public static function log(string $message, int $level = Debug::LOG_NORMAL): bool {
if (!self::$enabled || self::$loglevel < $level) return false; if (!self::$enabled || self::$loglevel < $level) return false;
@ -73,7 +86,7 @@ class Debug {
if (!$locked) { if (!$locked) {
fclose($fp); fclose($fp);
user_error("Unable to lock debugging log file: " . self::$logfile, E_USER_WARNING); user_error("Unable to lock debugging log file: " . self::$logfile, E_USER_WARNING);
return; return false;
} }
} }
@ -86,7 +99,7 @@ class Debug {
fclose($fp); fclose($fp);
if (self::$quiet) if (self::$quiet)
return; return false;
} else { } else {
user_error("Unable to open debugging log file: " . self::$logfile, E_USER_WARNING); user_error("Unable to open debugging log file: " . self::$logfile, E_USER_WARNING);
@ -94,5 +107,7 @@ class Debug {
} }
print "[$ts] $message\n"; print "[$ts] $message\n";
return true;
} }
} }