Преглед на файлове

Use PHPStan dynamicConstantNames (#5370)

https://phpstan.org/config-reference#constants
Avoid a few phpstan-ignore-next-line
Alexandre Alapetite преди 2 години
родител
ревизия
30c69ef147
променени са 6 файла, в които са добавени 18 реда и са изтрити 16 реда
  1. 1 1
      app/Models/Feed.php
  2. 0 2
      app/actualize_script.php
  3. 1 6
      lib/Minz/Log.php
  4. 5 5
      lib/lib_install.php
  5. 0 2
      lib/lib_rss.php
  6. 11 0
      phpstan.neon

+ 1 - 1
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

+ 0 - 2
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
 	}

+ 1 - 6
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);
 		}
 	}
 

+ 5 - 5
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',

+ 0 - 2
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 {

+ 11 - 0
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