aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorAlexandre Alapetite <alexandre@alapetite.fr>2023-05-04 19:47:54 +0200
committerGitHub <noreply@github.com>2023-05-04 19:47:54 +0200
commit30c69ef147059f440d304e7da5e0236d95e424fd (patch)
tree3aeec77db07a4fe23a3721e85dbe5175f98bc2b9
parent675c56f5799ed92a6aa3a8ad3d3d8d6636f444ec (diff)
downloadfreshrss-30c69ef147059f440d304e7da5e0236d95e424fd.tar.gz
freshrss-30c69ef147059f440d304e7da5e0236d95e424fd.zip
Use PHPStan dynamicConstantNames (#5370)
https://phpstan.org/config-reference#constants Avoid a few phpstan-ignore-next-line
-rw-r--r--app/Models/Feed.php2
-rwxr-xr-xapp/actualize_script.php2
-rw-r--r--lib/Minz/Log.php7
-rw-r--r--lib/lib_install.php10
-rw-r--r--lib/lib_rss.php2
-rw-r--r--phpstan.neon11
6 files changed, 18 insertions, 16 deletions
diff --git a/app/Models/Feed.php b/app/Models/Feed.php
index 6c840942b..f833b2834 100644
--- a/app/Models/Feed.php
+++ b/app/Models/Feed.php
@@ -363,7 +363,7 @@ class FreshRSS_Feed extends Minz_Model {
public function load(bool $loadDetails = false, bool $noCache = false): ?SimplePie {
if ($this->url != '') {
// @phpstan-ignore-next-line
- if (CACHE_PATH === false) {
+ if (CACHE_PATH == '') {
throw new Minz_FileNotExistException(
'CACHE_PATH',
Minz_Exception::ERROR
diff --git a/app/actualize_script.php b/app/actualize_script.php
index 160911f53..67dcc9631 100755
--- a/app/actualize_script.php
+++ b/app/actualize_script.php
@@ -30,11 +30,9 @@ define('SIMPLEPIE_SYSLOG_ENABLED', FreshRSS_Context::$system_conf->simplepie_sys
*/
function notice(string $message): void {
Minz_Log::notice($message, ADMIN_LOG);
- // @phpstan-ignore-next-line
if (!COPY_LOG_TO_SYSLOG && SIMPLEPIE_SYSLOG_ENABLED) {
syslog(LOG_NOTICE, $message);
}
- // @phpstan-ignore-next-line
if (defined('STDOUT') && !COPY_SYSLOG_TO_STDERR) {
fwrite(STDOUT, $message . "\n"); //Unbuffered
}
diff --git a/lib/Minz/Log.php b/lib/Minz/Log.php
index 20e8578be..f30aac7d1 100644
--- a/lib/Minz/Log.php
+++ b/lib/Minz/Log.php
@@ -56,7 +56,6 @@ class Minz_Log {
$log = '[' . date('r') . '] [' . $level_label . '] --- ' . $information . "\n";
- // @phpstan-ignore-next-line
if (defined('COPY_LOG_TO_SYSLOG') && COPY_LOG_TO_SYSLOG) {
syslog($level, '[' . $username . '] ' . trim($log));
}
@@ -80,7 +79,6 @@ class Minz_Log {
*/
protected static function ensureMaxLogSize(string $file_name): void {
$maxSize = defined('MAX_LOG_SIZE') ? MAX_LOG_SIZE : 1048576;
- // @phpstan-ignore-next-line
if ($maxSize > 0 && @filesize($file_name) > $maxSize) {
$fp = fopen($file_name, 'c+');
if ($fp && flock($fp, LOCK_EX)) {
@@ -95,10 +93,7 @@ class Minz_Log {
} else {
throw new Minz_PermissionDeniedException($file_name, Minz_Exception::ERROR);
}
- // @phpstan-ignore-next-line
- if ($fp) {
- fclose($fp);
- }
+ fclose($fp);
}
}
diff --git a/lib/lib_install.php b/lib/lib_install.php
index 23c902440..780115b63 100644
--- a/lib/lib_install.php
+++ b/lib/lib_install.php
@@ -41,14 +41,14 @@ function checkRequirements(string $dbType = ''): array {
$json = function_exists('json_encode');
$mbstring = extension_loaded('mbstring');
// @phpstan-ignore-next-line
- $data = DATA_PATH && touch(DATA_PATH . '/index.html'); // is_writable() is not reliable for a folder on NFS
+ $data = DATA_PATH != '' && touch(DATA_PATH . '/index.html'); // is_writable() is not reliable for a folder on NFS
// @phpstan-ignore-next-line
- $cache = CACHE_PATH && touch(CACHE_PATH . '/index.html');
+ $cache = CACHE_PATH != '' && touch(CACHE_PATH . '/index.html');
+ $tmp = TMP_PATH != '' && is_writable(TMP_PATH);
// @phpstan-ignore-next-line
- $tmp = TMP_PATH && is_writable(TMP_PATH);
+ $users = USERS_PATH != '' && touch(USERS_PATH . '/index.html');
// @phpstan-ignore-next-line
- $users = USERS_PATH && touch(USERS_PATH . '/index.html');
- $favicons = touch(DATA_PATH . '/favicons/index.html');
+ $favicons = DATA_PATH != '' && touch(DATA_PATH . '/favicons/index.html');
return array(
'php' => $php ? 'ok' : 'ko',
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index a7e03d4ea..e7cb7386a 100644
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@ -17,7 +17,6 @@ if (!function_exists('str_starts_with')) {
}
if (!function_exists('syslog')) {
- // @phpstan-ignore-next-line
if (COPY_SYSLOG_TO_STDERR && !defined('STDERR')) {
define('STDERR', fopen('php://stderr', 'w'));
}
@@ -31,7 +30,6 @@ if (!function_exists('syslog')) {
}
if (function_exists('openlog')) {
- // @phpstan-ignore-next-line
if (COPY_SYSLOG_TO_STDERR) {
openlog('FreshRSS', LOG_CONS | LOG_ODELAY | LOG_PID | LOG_PERROR, LOG_USER);
} else {
diff --git a/phpstan.neon b/phpstan.neon
index dd47c79ee..90c41aec7 100644
--- a/phpstan.neon
+++ b/phpstan.neon
@@ -20,6 +20,17 @@ parameters:
bootstrapFiles:
- cli/_cli.php
- lib/favicons.php
+ dynamicConstantNames:
+ - CACHE_PATH
+ - COPY_LOG_TO_SYSLOG
+ - COPY_SYSLOG_TO_STDERR
+ - DATA_PATH
+ - MAX_LOG_SIZE
+ - SIMPLEPIE_SYSLOG_ENABLED
+ - STDERR
+ - STDOUT
+ - TMP_PATH
+ - USERS_PATH
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon