aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcli/create-user.php4
-rwxr-xr-xcli/delete-user.php2
-rw-r--r--cli/i18n/I18nUsageValidator.php2
-rw-r--r--lib/Minz/ExtensionException.php4
-rw-r--r--lib/Minz/ExtensionManager.php2
-rw-r--r--lib/Minz/Log.php6
-rw-r--r--lib/Minz/Migrator.php4
-rw-r--r--lib/Minz/ModelPdo.php2
-rw-r--r--lib/Minz/Pdo.php2
-rw-r--r--lib/Minz/Request.php6
-rw-r--r--lib/favicons.php7
-rw-r--r--lib/http-conditional.php2
-rw-r--r--lib/lib_rss.php11
-rw-r--r--p/api/greader.php2
-rw-r--r--p/i/index.php2
15 files changed, 29 insertions, 29 deletions
diff --git a/cli/create-user.php b/cli/create-user.php
index 27e27f7a1..1da7f580d 100755
--- a/cli/create-user.php
+++ b/cli/create-user.php
@@ -10,7 +10,7 @@ if (!FreshRSS_user_Controller::checkUsername($username)) {
}
$usernames = listUsers();
-if (preg_grep("/^$username$/i", $usernames)) {
+if (preg_grep("/^$username$/i", $usernames) !== false) {
fail('FreshRSS warning: username already exists “' . $username . '”', EXIT_CODE_ALREADY_EXISTS);
}
@@ -31,7 +31,7 @@ if (!$ok) {
if (!empty($options['api_password'])) {
$username = cliInitUser($username);
$error = FreshRSS_api_Controller::updatePassword($options['api_password']);
- if ($error) {
+ if ($error !== false) {
fail($error);
}
}
diff --git a/cli/delete-user.php b/cli/delete-user.php
index fbbb2eebb..7b05cbe7a 100755
--- a/cli/delete-user.php
+++ b/cli/delete-user.php
@@ -19,7 +19,7 @@ if (!FreshRSS_user_Controller::checkUsername($username)) {
}
$usernames = listUsers();
-if (!preg_grep("/^$username$/i", $usernames)) {
+if (preg_grep("/^$username$/i", $usernames) === false) {
fail('FreshRSS error: username not found “' . $username . '”');
}
diff --git a/cli/i18n/I18nUsageValidator.php b/cli/i18n/I18nUsageValidator.php
index 0d85077f0..f8e3c6051 100644
--- a/cli/i18n/I18nUsageValidator.php
+++ b/cli/i18n/I18nUsageValidator.php
@@ -42,7 +42,7 @@ class I18nUsageValidator implements I18nValidatorInterface {
foreach ($this->reference as $file => $data) {
foreach ($data as $key => $value) {
$this->totalEntries++;
- if (preg_match('/\._$/', $key) && in_array(preg_replace('/\._$/', '', $key), $this->code, true)) {
+ if (preg_match('/\._$/', $key) === 1 && in_array(preg_replace('/\._$/', '', $key), $this->code, true)) {
continue;
}
if (!in_array($key, $this->code, true)) {
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');
}
diff --git a/p/api/greader.php b/p/api/greader.php
index b70a1f3f3..e42736869 100644
--- a/p/api/greader.php
+++ b/p/api/greader.php
@@ -1069,7 +1069,7 @@ final class GReaderAPI {
$include_target = $pathInfos[7];
if ($include_target != '' && !ctype_digit($include_target)) {
$include_target = empty($_SERVER['REQUEST_URI']) ? '' : $_SERVER['REQUEST_URI'];
- if (preg_match('#/reader/api/0/stream/contents/feed/([A-Za-z0-9\'!*()%$_.~+-]+)#', $include_target, $matches)) {
+ if (preg_match('#/reader/api/0/stream/contents/feed/([A-Za-z0-9\'!*()%$_.~+-]+)#', $include_target, $matches) === 1) {
$include_target = urldecode($matches[1]);
} else {
$include_target = '';
diff --git a/p/i/index.php b/p/i/index.php
index 6814a224f..76fb54a4b 100644
--- a/p/i/index.php
+++ b/p/i/index.php
@@ -62,7 +62,7 @@ if (!file_exists($applied_migrations_path)) {
$error = $e->getMessage();
}
- if ($error) {
+ if ($error !== false) {
syslog(LOG_INFO, 'FreshRSS Fatal error! ' . $error);
FreshRSS::killApp($error);
}