diff options
| author | 2023-07-07 21:53:17 +0200 | |
|---|---|---|
| committer | 2023-07-07 21:53:17 +0200 | |
| commit | 7f9594b8c7d7799f2e5f89328bd5981410db8cf0 (patch) | |
| tree | 67614f8f3d04e94139d19dad3dd438f3bd949368 /lib | |
| parent | 1db606bc1b6cf25d9b9c4bef362acdb964ce1e8a (diff) | |
fix many "Only booleans are allowed in an if condition" (#5501)
* fix many "Only booleans are allowed in an if condition"
* Update cli/create-user.php
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
* Update cli/i18n/I18nUsageValidator.php
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
* Fix several regressions and other minor things
* Fix another regression
* Update lib/http-conditional.php
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
---------
Co-authored-by: Luc <sanchezluc+freshrss@gmail.com>
Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/Minz/ExtensionException.php | 4 | ||||
| -rw-r--r-- | lib/Minz/ExtensionManager.php | 2 | ||||
| -rw-r--r-- | lib/Minz/Log.php | 6 | ||||
| -rw-r--r-- | lib/Minz/Migrator.php | 4 | ||||
| -rw-r--r-- | lib/Minz/ModelPdo.php | 2 | ||||
| -rw-r--r-- | lib/Minz/Pdo.php | 2 | ||||
| -rw-r--r-- | lib/Minz/Request.php | 6 | ||||
| -rw-r--r-- | lib/favicons.php | 7 | ||||
| -rw-r--r-- | lib/http-conditional.php | 2 | ||||
| -rw-r--r-- | lib/lib_rss.php | 11 |
10 files changed, 23 insertions, 23 deletions
diff --git a/lib/Minz/ExtensionException.php b/lib/Minz/ExtensionException.php index c5bba60a9..730730c1d 100644 --- a/lib/Minz/ExtensionException.php +++ b/lib/Minz/ExtensionException.php @@ -1,8 +1,8 @@ <?php class Minz_ExtensionException extends Minz_Exception { - public function __construct(string $message, ?string $extension_name = null, int $code = self::ERROR) { - if ($extension_name) { + public function __construct(string $message, string $extension_name = '', int $code = self::ERROR) { + if ($extension_name !== '') { $message = 'An error occurred in `' . $extension_name . '` extension with the message: ' . $message; } else { $message = 'An error occurred in an unnamed extension with the message: ' . $message; diff --git a/lib/Minz/ExtensionManager.php b/lib/Minz/ExtensionManager.php index 4fc62f254..88e793d39 100644 --- a/lib/Minz/ExtensionManager.php +++ b/lib/Minz/ExtensionManager.php @@ -145,7 +145,7 @@ final class Minz_ExtensionManager { continue; } $meta_raw_content = file_get_contents($metadata_filename) ?: ''; - /** @var array{'name':string,'entrypoint':string,'path':string,'author'?:string,'description'?:string,'version'?:string,'type'?:'system'|'user'}|null */ + /** @var array{'name':string,'entrypoint':string,'path':string,'author'?:string,'description'?:string,'version'?:string,'type'?:'system'|'user'}|null $meta_json */ $meta_json = json_decode($meta_raw_content, true); if (!$meta_json || !self::isValidMetadata($meta_json)) { // metadata.json is not a json file? Invalid! diff --git a/lib/Minz/Log.php b/lib/Minz/Log.php index 4dbdf42bc..60aba319d 100644 --- a/lib/Minz/Log.php +++ b/lib/Minz/Log.php @@ -81,12 +81,12 @@ class Minz_Log { $maxSize = defined('MAX_LOG_SIZE') ? MAX_LOG_SIZE : 1048576; if ($maxSize > 0 && @filesize($file_name) > $maxSize) { $fp = fopen($file_name, 'c+'); - if ($fp && flock($fp, LOCK_EX)) { - fseek($fp, -intval($maxSize / 2), SEEK_END); + if (is_resource($fp) && flock($fp, LOCK_EX)) { + fseek($fp, -(int)($maxSize / 2), SEEK_END); $content = fread($fp, $maxSize); rewind($fp); ftruncate($fp, 0); - fwrite($fp, $content ? $content : ''); + fwrite($fp, $content ?: ''); fwrite($fp, sprintf("[%s] [notice] --- Log rotate.\n", date('r'))); fflush($fp); flock($fp, LOCK_UN); diff --git a/lib/Minz/Migrator.php b/lib/Minz/Migrator.php index e723934f1..9508c0635 100644 --- a/lib/Minz/Migrator.php +++ b/lib/Minz/Migrator.php @@ -70,9 +70,7 @@ class Minz_Migrator } $migrator = new self($migrations_path); - if ($applied_migrations) { - $migrator->setAppliedVersions($applied_migrations); - } + $migrator->setAppliedVersions($applied_migrations); $results = $migrator->migrate(); foreach ($results as $migration => $result) { diff --git a/lib/Minz/ModelPdo.php b/lib/Minz/ModelPdo.php index a1b768bd9..63d8be2ca 100644 --- a/lib/Minz/ModelPdo.php +++ b/lib/Minz/ModelPdo.php @@ -69,7 +69,7 @@ class Minz_ModelPdo { $this->pdo->setPrefix($db['prefix'] . $this->current_user . '_'); break; case 'sqlite': - $dsn = 'sqlite:' . join_path(DATA_PATH, 'users', $this->current_user, 'db.sqlite'); + $dsn = 'sqlite:' . DATA_PATH . '/users/' . $this->current_user . '/db.sqlite'; $this->pdo = new Minz_PdoSqlite($dsn . $dsnParams, $db['user'], $db['password'], $driver_options); $this->pdo->setPrefix(''); break; diff --git a/lib/Minz/Pdo.php b/lib/Minz/Pdo.php index 05015040a..474602c52 100644 --- a/lib/Minz/Pdo.php +++ b/lib/Minz/Pdo.php @@ -28,7 +28,7 @@ abstract class Minz_Pdo extends PDO { } protected function preSql(string $statement): string { - if (preg_match('/^(?:UPDATE|INSERT|DELETE)/i', $statement)) { + if (preg_match('/^(?:UPDATE|INSERT|DELETE)/i', $statement) === 1) { invalidateHttpCache(); } return $this->autoPrefix($statement); diff --git a/lib/Minz/Request.php b/lib/Minz/Request.php index 95cb220bf..c5adb02e1 100644 --- a/lib/Minz/Request.php +++ b/lib/Minz/Request.php @@ -306,7 +306,7 @@ class Minz_Request { return false; } $host = parse_url($address, PHP_URL_HOST); - if (!$host) { + if (!is_string($host)) { return false; } @@ -358,7 +358,7 @@ class Minz_Request { $notif = null; Minz_Session::lock(); $requests = Minz_Session::param('requests'); - if ($requests) { + if (is_array($requests)) { //Delete abandoned notifications $requests = array_filter($requests, static function (array $r) { return isset($r['time']) && $r['time'] > time() - 3600; }); @@ -454,7 +454,7 @@ class Minz_Request { * @return array<string> */ public static function getPreferredLanguages(): array { - if (preg_match_all('/(^|,)\s*(?P<lang>[^;,]+)/', $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? '', $matches)) { + if (preg_match_all('/(^|,)\s*(?P<lang>[^;,]+)/', $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? '', $matches) > 0) { return $matches['lang']; } return array('en'); diff --git a/lib/favicons.php b/lib/favicons.php index b5c70d975..8da38c519 100644 --- a/lib/favicons.php +++ b/lib/favicons.php @@ -78,13 +78,14 @@ function searchFavicon(string &$url): string { $href = trim($link->getAttribute('href')); if (substr($href, 0, 2) === '//') { // Case of protocol-relative URLs - if (preg_match('%^(https?:)//%i', $url, $matches)) { + if (preg_match('%^(https?:)//%i', $url, $matches) === 1) { $href = $matches[1] . $href; } else { $href = 'https:' . $href; } } - if (!checkUrl($href, false)) { + $checkUrl = checkUrl($href, false); + if (is_string($checkUrl)) { $href = SimplePie_IRI::absolutize($url, $href); } $favicon = downloadHttp($href, array( @@ -119,6 +120,6 @@ function download_favicon(string $url, string $dest): bool { } } } - return ($favicon != '' && file_put_contents($dest, $favicon)) || + return ($favicon != '' && file_put_contents($dest, $favicon) > 0) || @copy(DEFAULT_FAVICON, $dest); } diff --git a/lib/http-conditional.php b/lib/http-conditional.php index 1a1b6a6dc..21382b735 100644 --- a/lib/http-conditional.php +++ b/lib/http-conditional.php @@ -182,7 +182,7 @@ function httpConditional(int $UnixTimeStamp, int $cacheSeconds = 0, int $cachePr * Reference rfc2616-sec14.html#sec14.11 */ function _httpConditionalCallBack(string $buffer, int $mode = 5): string { - if (extension_loaded('zlib') && (!ini_get('zlib.output_compression'))) { + if (extension_loaded('zlib') && (ini_get('zlib.output_compression') == false)) { $buffer2 = ob_gzhandler($buffer, $mode) ?: ''; //Will check HTTP_ACCEPT_ENCODING and put correct headers such as Vary //rfc2616-sec14.html#sec14.44 if (strlen($buffer2) > 1) //When ob_gzhandler succeeded $buffer = $buffer2; diff --git a/lib/lib_rss.php b/lib/lib_rss.php index 01ec7fa98..ec00513e2 100644 --- a/lib/lib_rss.php +++ b/lib/lib_rss.php @@ -116,14 +116,14 @@ function checkUrl(string $url, bool $fixScheme = true) { if ($url == '') { return ''; } - if ($fixScheme && !preg_match('#^https?://#i', $url)) { + if ($fixScheme && preg_match('#^https?://#i', $url) !== 1) { $url = 'https://' . ltrim($url, '/'); } $url = idn_to_puny($url); //PHP bug #53474 IDN $urlRelaxed = str_replace('_', 'z', $url); //PHP discussion #64948 Underscore - if (filter_var($urlRelaxed, FILTER_VALIDATE_URL)) { + if (is_string(filter_var($urlRelaxed, FILTER_VALIDATE_URL))) { return $url; } else { return false; @@ -244,6 +244,7 @@ function sensitive_log($log) { /** * @param array<string,mixed> $attributes + * @throws FreshRSS_Context_Exception */ function customSimplePie(array $attributes = array()): SimplePie { if (FreshRSS_Context::$system_conf === null) { @@ -258,13 +259,13 @@ function customSimplePie(array $attributes = array()): SimplePie { $simplePie->set_cache_duration($limits['cache_duration']); $simplePie->enable_order_by_date(false); - $feed_timeout = empty($attributes['timeout']) ? 0 : intval($attributes['timeout']); + $feed_timeout = empty($attributes['timeout']) ? 0 : (int)$attributes['timeout']; $simplePie->set_timeout($feed_timeout > 0 ? $feed_timeout : $limits['timeout']); $curl_options = FreshRSS_Context::$system_conf->curl_options; if (isset($attributes['ssl_verify'])) { $curl_options[CURLOPT_SSL_VERIFYHOST] = $attributes['ssl_verify'] ? 2 : 0; - $curl_options[CURLOPT_SSL_VERIFYPEER] = $attributes['ssl_verify'] ? true : false; + $curl_options[CURLOPT_SSL_VERIFYPEER] = (bool)$attributes['ssl_verify']; if (!$attributes['ssl_verify']) { $curl_options[CURLOPT_SSL_CIPHER_LIST] = 'DEFAULT@SECLEVEL=1'; } @@ -468,7 +469,7 @@ function httpGet(string $url, string $cachePath, string $type = 'html', array $a if (isset($attributes['ssl_verify'])) { curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $attributes['ssl_verify'] ? 2 : 0); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $attributes['ssl_verify'] ? true : false); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (bool)$attributes['ssl_verify']); if (!$attributes['ssl_verify']) { curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'DEFAULT@SECLEVEL=1'); } |
