From 77a98134b83a9dfe44081641847ce2a842c05c24 Mon Sep 17 00:00:00 2001 From: wn_ Date: Mon, 1 Nov 2021 16:03:28 +0000 Subject: Address PHPStan warnings in 'classes/config.php'. ------ ----------------------------------------------------------------------- Line classes/config.php ------ ----------------------------------------------------------------------- 3 Constant Config::_ENVVAR_PREFIX is unused. 177 Constant Config::_DEFAULTS is unused. 237 Property Config::$schema_version is never read, only written. 352 Property Config::$migrations (Db_Migrations) in empty() is not falsy. ------ ----------------------------------------------------------------------- --- classes/config.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'classes') diff --git a/classes/config.php b/classes/config.php index be4ecde36..53a31b61c 100644 --- a/classes/config.php +++ b/classes/config.php @@ -234,10 +234,9 @@ class Config { private static $instance; private $params = []; - private $schema_version = null; private $version = []; - /** @var Db_Migrations $migrations */ + /** @var Db_Migrations|null $migrations */ private $migrations; public static function get_instance() : Config { @@ -255,10 +254,10 @@ class Config { $ref = new ReflectionClass(get_class($this)); foreach ($ref->getConstants() as $const => $cvalue) { - if (isset($this::_DEFAULTS[$const])) { - $override = getenv($this::_ENVVAR_PREFIX . $const); + if (isset(self::_DEFAULTS[$const])) { + $override = getenv(self::_ENVVAR_PREFIX . $const); - list ($defval, $deftype) = $this::_DEFAULTS[$const]; + list ($defval, $deftype) = self::_DEFAULTS[$const]; $this->params[$cvalue] = [ self::cast_to($override !== false ? $override : $defval, $deftype), $deftype ]; } @@ -383,7 +382,7 @@ class Config { } private function _add(string $param, string $default, int $type_hint) { - $override = getenv($this::_ENVVAR_PREFIX . $param); + $override = getenv(self::_ENVVAR_PREFIX . $param); $this->params[$param] = [ self::cast_to($override !== false ? $override : $default, $type_hint), $type_hint ]; } -- cgit v1.2.3-54-g00ecf From 7d8837ca17a34230e85b05c99f2fa16ef8bdc1d7 Mon Sep 17 00:00:00 2001 From: wn_ Date: Mon, 1 Nov 2021 20:28:00 +0000 Subject: Address PHPStan warnings in 'classes/db.php'. ------ -------------------------------------------------- Line classes/db.php ------ -------------------------------------------------- 7 Property Db::$link is unused. 86 Property Db::pdo (PDO) in empty() is not falsy. ------ -------------------------------------------------- --- classes/db.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'classes') diff --git a/classes/db.php b/classes/db.php index a09c44628..7b669cf32 100755 --- a/classes/db.php +++ b/classes/db.php @@ -4,9 +4,7 @@ class Db /** @var Db $instance */ private static $instance; - private $link; - - /** @var PDO $pdo */ + /** @var PDO|null $pdo */ private $pdo; function __construct() { -- cgit v1.2.3-54-g00ecf From 5b17c44e70689d4750e87da8801662baf21c5b6d Mon Sep 17 00:00:00 2001 From: wn_ Date: Mon, 1 Nov 2021 20:29:38 +0000 Subject: Address PHPStan warning in 'classes/feeditem/common.php'. ------ --------------------------------------------- Line classes/feeditem/common.php ------ --------------------------------------------- 194 No error to ignore is reported on line 194. ------ --------------------------------------------- --- classes/feeditem/common.php | 1 - 1 file changed, 1 deletion(-) (limited to 'classes') diff --git a/classes/feeditem/common.php b/classes/feeditem/common.php index b4774941f..18afeaa94 100755 --- a/classes/feeditem/common.php +++ b/classes/feeditem/common.php @@ -190,7 +190,6 @@ abstract class FeedItem_Common extends FeedItem { }, $tmp); // remove empty values - // @phpstan-ignore-next-line $tmp = array_filter($tmp, 'strlen'); asort($tmp); -- cgit v1.2.3-54-g00ecf From 72cf4f1f0de570b9944a8d5dca6aed80e1658780 Mon Sep 17 00:00:00 2001 From: wn_ Date: Mon, 1 Nov 2021 20:30:24 +0000 Subject: Address PHPStan warning in 'classes/feeds.php'. ------ ------------------------------------ Line classes/feeds.php ------ ------------------------------------ 8 Property Feeds::$params is unused. ------ ------------------------------------ --- classes/feeds.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'classes') diff --git a/classes/feeds.php b/classes/feeds.php index ea9158949..987123a21 100755 --- a/classes/feeds.php +++ b/classes/feeds.php @@ -5,8 +5,6 @@ class Feeds extends Handler_Protected { const NEVER_GROUP_FEEDS = [ -6, 0 ]; const NEVER_GROUP_BY_DATE = [ -2, -1, -3 ]; - private $params; - private $viewfeed_timestamp; private $viewfeed_timestamp_last; -- cgit v1.2.3-54-g00ecf From a7a59fe0e2402df03c383d16d3bfb1c28ecf93b5 Mon Sep 17 00:00:00 2001 From: wn_ Date: Mon, 1 Nov 2021 20:30:55 +0000 Subject: Address PHPStan warning in 'classes/logger/sql.php'. ------ -------------------------------------- Line classes/logger/sql.php ------ -------------------------------------- 4 Property Logger_SQL::$pdo is unused. ------ -------------------------------------- --- classes/logger/sql.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'classes') diff --git a/classes/logger/sql.php b/classes/logger/sql.php index 784ebef31..0f6177a5b 100755 --- a/classes/logger/sql.php +++ b/classes/logger/sql.php @@ -1,8 +1,6 @@ Date: Mon, 1 Nov 2021 20:31:42 +0000 Subject: Address PHPStan warnings in 'classes/pluginhost.php'. ------ -------------------------------------------------------------------- Line classes/pluginhost.php ------ -------------------------------------------------------------------- 16 Property PluginHost::$last_registered is never read, only written. 386 If condition is always true. ------ -------------------------------------------------------------------- --- classes/pluginhost.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'classes') diff --git a/classes/pluginhost.php b/classes/pluginhost.php index f067543bb..b506a957a 100755 --- a/classes/pluginhost.php +++ b/classes/pluginhost.php @@ -13,7 +13,6 @@ class PluginHost { private $api_methods = array(); private $plugin_actions = array(); private $owner_uid; - private $last_registered; private $data_loaded; private static $instance; @@ -383,7 +382,7 @@ class PluginHost { if (!isset($this->plugins[$class])) { try { - if (file_exists($file)) require_once $file; + require_once $file; } catch (Error $err) { user_error($err, E_USER_WARNING); continue; @@ -404,8 +403,6 @@ class PluginHost { _bind_textdomain_codeset($class, "UTF-8"); } - $this->last_registered = $class; - try { switch ($kind) { case $this::KIND_SYSTEM: -- cgit v1.2.3-54-g00ecf From a38892d5d78a60e10e572e6473dbe75444462fb6 Mon Sep 17 00:00:00 2001 From: wn_ Date: Mon, 1 Nov 2021 20:32:43 +0000 Subject: Address PHPStan warning in 'classes/pref/prefs.php'. ------ ------------------------------------------------ Line classes/pref/prefs.php ------ ------------------------------------------------ 1328 Expression on left side of ?? is not nullable. ------ ------------------------------------------------ --- classes/pref/prefs.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'classes') diff --git a/classes/pref/prefs.php b/classes/pref/prefs.php index cb666e945..c47a99469 100644 --- a/classes/pref/prefs.php +++ b/classes/pref/prefs.php @@ -1325,7 +1325,7 @@ class Pref_Prefs extends Handler_Protected { } function activateprofile() { - $id = (int) $_REQUEST['id'] ?? 0; + $id = (int) ($_REQUEST['id'] ?? 0); $profile = ORM::for_table('ttrss_settings_profiles') ->where('owner_uid', $_SESSION['uid']) -- cgit v1.2.3-54-g00ecf From ac5a4f5937d2d763b6293d3db644c9f30aa704b6 Mon Sep 17 00:00:00 2001 From: wn_ Date: Mon, 1 Nov 2021 20:33:46 +0000 Subject: Address PHPStan warning in 'classes/pref/users.php'. ------ ------------------------------- Line classes/pref/users.php ------ ------------------------------- 170 If condition is always false. ------ ------------------------------- --- classes/pref/users.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'classes') diff --git a/classes/pref/users.php b/classes/pref/users.php index 76a879efd..aeba296b2 100644 --- a/classes/pref/users.php +++ b/classes/pref/users.php @@ -167,7 +167,7 @@ class Pref_Users extends Handler_Administrative { $user->created = Db::NOW(); $user->save(); - if ($new_uid = UserHelper::find_user_by_login($login)) { + if (!is_null(UserHelper::find_user_by_login($login))) { print T_sprintf("Added user %s with password %s", $login, $new_password); } else { -- cgit v1.2.3-54-g00ecf From 9dac9c5a0db520697794c00d29424e617aca55bd Mon Sep 17 00:00:00 2001 From: wn_ Date: Mon, 1 Nov 2021 20:36:48 +0000 Subject: Address PHPStan warnings in 'classes/urlhelper.php'. Intentionally skipping the line 66 one for now; adding an 'is_array' check clears the warning, but there's a larger topic of how to handle an invalid '' that doesn't result in an array. ------ --------------------------------------------------------------------- Line classes/urlhelper.php ------ --------------------------------------------------------------------- 66 Offset 'path' on array{scheme: string} in isset() does not exist. 165 Parameter #2 $associative of function get_headers expects bool, int given. 167 Parameter #2 $associative of function get_headers expects bool, int given. 278 Negated boolean expression is always true. 309 Negated boolean expression is always true. ------ --------------------------------------------------------------------- --- classes/urlhelper.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'classes') diff --git a/classes/urlhelper.php b/classes/urlhelper.php index 0e4834b72..4d11b5a4d 100644 --- a/classes/urlhelper.php +++ b/classes/urlhelper.php @@ -162,8 +162,12 @@ class UrlHelper { $context = stream_context_create($context_options); + // PHP 8 changed the second param from int to bool, but we still support PHP >= 7.1.0 + // @phpstan-ignore-next-line $headers = get_headers($url, 0, $context); } else { + // PHP 8 changed the second param from int to bool, but we still support PHP >= 7.1.0 + // @phpstan-ignore-next-line $headers = get_headers($url, 0); } @@ -275,7 +279,7 @@ class UrlHelper { curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout ? $timeout : Config::get(Config::FILE_FETCH_CONNECT_TIMEOUT)); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout ? $timeout : Config::get(Config::FILE_FETCH_TIMEOUT)); - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, !ini_get("open_basedir") && $followlocation); + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $followlocation); curl_setopt($ch, CURLOPT_MAXREDIRS, 20); curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); @@ -283,6 +287,7 @@ class UrlHelper { curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); curl_setopt($ch, CURLOPT_USERAGENT, $useragent ? $useragent : Config::get_user_agent()); curl_setopt($ch, CURLOPT_ENCODING, ""); + curl_setopt($ch, CURLOPT_COOKIEJAR, "/dev/null"); if ($http_referrer) curl_setopt($ch, CURLOPT_REFERER, $http_referrer); @@ -306,10 +311,6 @@ class UrlHelper { } - if (!ini_get("open_basedir")) { - curl_setopt($ch, CURLOPT_COOKIEJAR, "/dev/null"); - } - if (Config::get(Config::HTTP_PROXY)) { curl_setopt($ch, CURLOPT_PROXY, Config::get(Config::HTTP_PROXY)); } -- cgit v1.2.3-54-g00ecf