summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwn_ <[email protected]>2022-08-12 14:13:26 +0000
committerwn_ <[email protected]>2022-08-12 14:13:26 +0000
commit93fd85df6f73732d3a6ed280d26224e1877c954f (patch)
tree2b2a4fe2adb98d9e2a975b31069cca7bf66c4a04
parented2cbeffcc456a86726b52d37c977a35b895968c (diff)
Switch to direct type declarations of class properties.
-rw-r--r--classes/db/migrations.php36
-rw-r--r--classes/debug.php31
-rw-r--r--classes/diskcache.php6
-rw-r--r--classes/handler.php6
-rw-r--r--classes/mailer.php4
-rwxr-xr-xclasses/pluginhost.php33
-rw-r--r--classes/pref/prefs.php10
-rw-r--r--classes/urlhelper.php33
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 @@
<?php
class Db_Migrations {
- // TODO: class properties can be switched to PHP typing if/when the minimum PHP_VERSION is raised to 7.4.0+
- /** @var string */
- private $base_filename = "schema.sql";
-
- /** @var string */
- private $base_path;
-
- /** @var string */
- private $migrations_path;
-
- /** @var string */
- private $migrations_table;
-
- /** @var bool */
- private $base_is_latest;
-
- /** @var PDO */
- private $pdo;
-
- /** @var int */
- private $cached_version = 0;
-
- /** @var int */
- private $cached_max_version = 0;
-
- /** @var int */
- private $max_version_override;
+ private string $base_filename = "schema.sql";
+ private string $base_path;
+ private string $migrations_path;
+ private string $migrations_table;
+ private bool $base_is_latest;
+ private PDO $pdo;
+ private int $cached_version = 0;
+ private int $cached_max_version = 0;
+ private int $max_version_override;
function __construct() {
$this->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 @@
<?php
class DiskCache {
- // TODO: class properties can be switched to PHP typing if/when the minimum PHP_VERSION is raised to 7.4.0+
- /** @var string */
- private $dir;
+ private string $dir;
/**
* https://stackoverflow.com/a/53662733
*
* @var array<string, string>
*/
- 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 @@
<?php
class Handler implements IHandler {
- // TODO: class properties can be switched to PHP typing if/when the minimum PHP_VERSION is raised to 7.4.0+
- /** @var PDO */
- protected $pdo;
+ protected PDO $pdo;
/** @var array<int|string, mixed> */
- protected $args;
+ protected array $args;
/**
* @param array<int|string, mixed> $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 @@
<?php
class Mailer {
- // TODO: class properties can be switched to PHP typing if/when the minimum PHP_VERSION is raised to 7.4.0+
- /** @var string */
- private $last_error = "";
+ private string $last_error = "";
/**
* @param array<string, mixed> $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 @@
<?php
class PluginHost {
- // TODO: class properties can be switched to PHP typing if/when the minimum PHP_VERSION is raised to 7.4.0+
- /** @var PDO|null */
- private $pdo = null;
+ private ?PDO $pdo = null;
/**
* separate handle for plugin data so transaction while saving wouldn't clash with possible main
* tt-rss code transactions; only initialized when first needed
- *
- * @var PDO|null
*/
- private $pdo_data = null;
+ private ?PDO $pdo_data = null;
/** @var array<string, array<int, array<int, Plugin>>> hook types -> priority levels -> Plugins */
- private $hooks = [];
+ private array $hooks = [];
/** @var array<string, Plugin> */
- private $plugins = [];
+ private array $plugins = [];
/** @var array<string, array<string, Plugin>> handler type -> method type -> Plugin */
- private $handlers = [];
+ private array $handlers = [];
/** @var array<string, array{'description': string, 'suffix': string, 'arghelp': string, 'class': Plugin}> command type -> details array */
- private $commands = [];
+ private array $commands = [];
/** @var array<string, array<string, mixed>> plugin name -> (potential profile array) -> key -> value */
- private $storage = [];
+ private array $storage = [];
/** @var array<int, array<int, array{'id': int, 'title': string, 'sender': Plugin, 'icon': string}>> */
- private $feeds = [];
+ private array $feeds = [];
/** @var array<string, Plugin> API method name, Plugin sender */
- private $api_methods = [];
+ private array $api_methods = [];
/** @var array<string, array<int, array{'action': string, 'description': string, 'sender': Plugin}>> */
- 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<Prefs::*, array<int, string>> */
- private $pref_help = [];
+ private array $pref_help = [];
/** @var array<string, array<int, string>> pref items are Prefs::*|Pref_Prefs::BLOCK_SEPARATOR (PHPStan was complaining) */
- private $pref_item_map = [];
+ private array $pref_item_map = [];
/** @var array<string, string> */
- private $pref_help_bottom = [];
+ private array $pref_help_bottom = [];
/** @var array<int, string> */
- 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<string, string|int> $parts