From 93fd85df6f73732d3a6ed280d26224e1877c954f Mon Sep 17 00:00:00 2001 From: wn_ Date: Fri, 12 Aug 2022 14:13:26 +0000 Subject: [PATCH] Switch to direct type declarations of class properties. --- classes/db/migrations.php | 36 +++++++++--------------------------- classes/debug.php | 31 +++++++++---------------------- classes/diskcache.php | 6 ++---- classes/handler.php | 6 ++---- classes/mailer.php | 4 +--- classes/pluginhost.php | 33 +++++++++++++-------------------- classes/pref/prefs.php | 10 ++++------ classes/urlhelper.php | 33 ++++++++------------------------- 8 files changed, 48 insertions(+), 111 deletions(-) diff --git a/classes/db/migrations.php b/classes/db/migrations.php index aecd9186c..5f969c513 100644 --- a/classes/db/migrations.php +++ b/classes/db/migrations.php @@ -1,33 +1,15 @@ pdo = Db::pdo(); diff --git a/classes/debug.php b/classes/debug.php index 4777e8c74..40fa27377 100644 --- a/classes/debug.php +++ b/classes/debug.php @@ -12,44 +12,31 @@ class Debug { Debug::LOG_EXTENDED, ]; - // TODO: class properties can be switched to PHP typing if/when the minimum PHP_VERSION is raised to 7.4.0+ /** * @deprecated - * @var int */ - public static $LOG_DISABLED = self::LOG_DISABLED; + public static int $LOG_DISABLED = self::LOG_DISABLED; /** * @deprecated - * @var int */ - public static $LOG_NORMAL = self::LOG_NORMAL; + public static int $LOG_NORMAL = self::LOG_NORMAL; /** * @deprecated - * @var int */ - public static $LOG_VERBOSE = self::LOG_VERBOSE; + public static int $LOG_VERBOSE = self::LOG_VERBOSE; /** * @deprecated - * @var int */ - public static $LOG_EXTENDED = self::LOG_EXTENDED; + public static int $LOG_EXTENDED = self::LOG_EXTENDED; - /** @var bool */ - private static $enabled = false; + private static bool $enabled = false; + private static bool $quiet = false; + private static ?string $logfile = null; - /** @var bool */ - private static $quiet = false; - - /** @var string|null */ - private static $logfile = null; - - /** - * @var int Debug::LOG_* - */ - private static $loglevel = self::LOG_NORMAL; + private static int $loglevel = self::LOG_NORMAL; public static function set_logfile(string $logfile): void { self::$logfile = $logfile; @@ -70,7 +57,7 @@ class Debug { /** * @param Debug::LOG_* $level */ - public static function set_loglevel($level): void { + public static function set_loglevel(int $level): void { self::$loglevel = $level; } diff --git a/classes/diskcache.php b/classes/diskcache.php index 34bba25f1..01c713b99 100644 --- a/classes/diskcache.php +++ b/classes/diskcache.php @@ -1,15 +1,13 @@ */ - private $mimeMap = [ + private array $mimeMap = [ 'video/3gpp2' => '3g2', 'video/3gp' => '3gp', 'video/3gpp' => '3gp', diff --git a/classes/handler.php b/classes/handler.php index 806c9cfbe..5b54570d8 100644 --- a/classes/handler.php +++ b/classes/handler.php @@ -1,11 +1,9 @@ */ - protected $args; + protected array $args; /** * @param array $args diff --git a/classes/mailer.php b/classes/mailer.php index 60b1ce4fd..76c9abf8e 100644 --- a/classes/mailer.php +++ b/classes/mailer.php @@ -1,8 +1,6 @@ $params diff --git a/classes/pluginhost.php b/classes/pluginhost.php index 6ab4ac806..4c71d0cef 100755 --- a/classes/pluginhost.php +++ b/classes/pluginhost.php @@ -1,49 +1,42 @@ >> hook types -> priority levels -> Plugins */ - private $hooks = []; + private array $hooks = []; /** @var array */ - private $plugins = []; + private array $plugins = []; /** @var array> handler type -> method type -> Plugin */ - private $handlers = []; + private array $handlers = []; /** @var array command type -> details array */ - private $commands = []; + private array $commands = []; /** @var array> plugin name -> (potential profile array) -> key -> value */ - private $storage = []; + private array $storage = []; /** @var array> */ - private $feeds = []; + private array $feeds = []; /** @var array API method name, Plugin sender */ - private $api_methods = []; + private array $api_methods = []; /** @var array> */ - private $plugin_actions = []; + private array $plugin_actions = []; - /** @var int|null */ - private $owner_uid = null; + private ?int $owner_uid = null; - /** @var bool */ - private $data_loaded = false; + private bool $data_loaded = false; - /** @var PluginHost|null */ - private static $instance = null; + private static ?PluginHost $instance = null; const API_VERSION = 2; const PUBLIC_METHOD_DELIMITER = "--"; diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index 7acd06aa4..3e651297e 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -2,18 +2,17 @@ use chillerlan\QRCode; class Pref_Prefs extends Handler_Protected { - // TODO: class properties can be switched to PHP typing if/when the minimum PHP_VERSION is raised to 7.4.0+ /** @var array> */ - private $pref_help = []; + private array $pref_help = []; /** @var array> pref items are Prefs::*|Pref_Prefs::BLOCK_SEPARATOR (PHPStan was complaining) */ - private $pref_item_map = []; + private array $pref_item_map = []; /** @var array */ - private $pref_help_bottom = []; + private array $pref_help_bottom = []; /** @var array */ - private $pref_blacklist = []; + private array $pref_blacklist = []; private const BLOCK_SEPARATOR = 'BLOCK_SEPARATOR'; @@ -26,7 +25,6 @@ class Pref_Prefs extends Handler_Protected { const PI_ERR_PLUGIN_NOT_FOUND = "PI_ERR_PLUGIN_NOT_FOUND"; const PI_ERR_NO_WORKDIR = "PI_ERR_NO_WORKDIR"; - /** @param string $method */ function csrf_ignore(string $method) : bool { $csrf_ignored = array("index", "updateself", "otpqrcode"); diff --git a/classes/urlhelper.php b/classes/urlhelper.php index bb51f5d06..da812d422 100644 --- a/classes/urlhelper.php +++ b/classes/urlhelper.php @@ -10,31 +10,14 @@ class UrlHelper { "application/x-bittorrent" => [ "magnet" ], ]; - // TODO: class properties can be switched to PHP typing if/when the minimum PHP_VERSION is raised to 7.4.0+ - /** @var string */ - static $fetch_last_error; - - /** @var int */ - static $fetch_last_error_code; - - /** @var string */ - static $fetch_last_error_content; - - /** @var string */ - static $fetch_last_content_type; - - /** @var string */ - static $fetch_last_modified; - - - /** @var string */ - static $fetch_effective_url; - - /** @var string */ - static $fetch_effective_ip_addr; - - /** @var bool */ - static $fetch_curl_used; + static string $fetch_last_error; + static int $fetch_last_error_code; + static string $fetch_last_error_content; + static string $fetch_last_content_type; + static string $fetch_last_modified; + static string $fetch_effective_url; + static string $fetch_effective_ip_addr; + static bool $fetch_curl_used; /** * @param array $parts