A free, self-hostable news aggregator…
Automated test towards PHPStan level 6 (#5230)
Alexandre Alapetitef3af3f0f3d4d
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.ymlindex 6e1e6b0a6..ce0be20ce 100644--- a/.github/workflows/tests.yml+++ b/.github/workflows/tests.yml@@ -49,6 +49,9 @@ jobs:- name: PHPStanrun: composer run-script phpstan+ - name: PHPStan Next Level+ run: composer run-script phpstan-next+# NPM tests- name: Uses Node.jsdiff --git a/app/Models/SystemConfiguration.php b/app/Models/SystemConfiguration.phpindex 9fc79969d..2eed1f02a 100644--- a/app/Models/SystemConfiguration.php+++ b/app/Models/SystemConfiguration.php@@ -27,7 +27,7 @@*/final class FreshRSS_SystemConfiguration extends Minz_Configuration {- public static function init($config_filename, $default_filename = null): FreshRSS_SystemConfiguration {+ public static function init(string $config_filename, ?string $default_filename = null): FreshRSS_SystemConfiguration {parent::register('system', $config_filename, $default_filename);return parent::get('system');}diff --git a/app/Models/UserConfiguration.php b/app/Models/UserConfiguration.phpindex f539268ae..77e1d2821 100644--- a/app/Models/UserConfiguration.php+++ b/app/Models/UserConfiguration.php@@ -71,7 +71,8 @@*/final class FreshRSS_UserConfiguration extends Minz_Configuration {- public static function init($config_filename, $default_filename = null, $configuration_setter = null): FreshRSS_UserConfiguration {+ public static function init(string $config_filename, ?string $default_filename = null,+ ?FreshRSS_ConfigurationSetter $configuration_setter = null): FreshRSS_UserConfiguration {parent::register('user', $config_filename, $default_filename, $configuration_setter);return parent::get('user');}diff --git a/app/actualize_script.php b/app/actualize_script.phpindex bad466e64..8e445b1e7 100755--- a/app/actualize_script.php+++ b/app/actualize_script.php@@ -25,7 +25,7 @@ define('SIMPLEPIE_SYSLOG_ENABLED', FreshRSS_Context::$system_conf->simplepie_sys* Writes to FreshRSS admin log, and if it is not already done by default,* writes to syslog (only if simplepie_syslog_enabled in FreshRSS configuration) and to STDOUT*/-function notice($message) {+function notice(string $message): void {Minz_Log::notice($message, ADMIN_LOG);// @phpstan-ignore-next-lineif (!COPY_LOG_TO_SYSLOG && SIMPLEPIE_SYSLOG_ENABLED) {diff --git a/app/views/helpers/export/opml.phtml b/app/views/helpers/export/opml.phtmlindex 64c83c960..64dc18eba 100644--- a/app/views/helpers/export/opml.phtml+++ b/app/views/helpers/export/opml.phtml@@ -2,8 +2,9 @@/*** @param array<FreshRSS_Feed> $feeds+ * @return array<array<string,string|null>>*/-function feedsToOutlines($feeds, $excludeMutedFeeds = false): array {+function feedsToOutlines($feeds, bool $excludeMutedFeeds = false): array {$outlines = [];foreach ($feeds as $feed) {if ($feed->mute() && $excludeMutedFeeds) {diff --git a/composer.json b/composer.jsonindex 2234a0e13..461c2f457 100644--- a/composer.json+++ b/composer.json@@ -57,6 +57,7 @@"phpcs": "phpcs . -s","phpcbf": "phpcbf . -p -s","phpstan": "phpstan analyse --memory-limit 512M .",+ "phpstan-next": "phpstan analyse --level 6 --memory-limit 512M $(find . -type d -name 'vendor' -prune -o -name '*.php' -o -name '*.phtml' | grep -Fxvf ./tests/phpstan-next.txt | sort | paste -s)","phpunit": "phpunit --bootstrap ./tests/bootstrap.php --verbose ./tests","translations": "cli/manipulate.translation.php -a format","test": [@@ -64,7 +65,8 @@"@phtml-lint","@phpunit","@phpcs",- "@phpstan"+ "@phpstan",+ "@phpstan-next"],"fix": ["@translations",diff --git a/tests/phpstan-next.txt b/tests/phpstan-next.txtnew file mode 100644index 000000000..7f8d5e4e4--- /dev/null+++ b/tests/phpstan-next.txt@@ -0,0 +1,93 @@+# List of files, which are not yet passing PHPStan level 6 https://phpstan.org/user-guide/rule-levels+# https://github.com/FreshRSS/FreshRSS/issues/4112+# Used for automated tests to avoid regressions in files already passing that level.+# Can be regenerated with something like:+# find . -type d -name 'vendor' -prune -o -name '*.php' -exec sh -c 'vendor/bin/phpstan analyse --level 6 --memory-limit 512M {} >/dev/null 2>/dev/null || echo {}' \;++./app/Controllers/extensionController.php+./app/Controllers/feedController.php+./app/Controllers/indexController.php+./app/Controllers/updateController.php+./app/Controllers/userController.php+./app/Exceptions/AlreadySubscribedException.php+./app/Exceptions/BadUrlException.php+./app/Exceptions/FeedNotAddedException.php+./app/Exceptions/ZipException.php+./app/install.php+./app/Mailers/UserMailer.php+./app/Models/Auth.php+./app/Models/BooleanSearch.php+./app/Models/Category.php+./app/Models/CategoryDAO.php+./app/Models/CategoryDAOSQLite.php+./app/Models/ConfigurationSetter.php+./app/Models/Context.php+./app/Models/DatabaseDAO.php+./app/Models/DatabaseDAOPGSQL.php+./app/Models/DatabaseDAOSQLite.php+./app/Models/Entry.php+./app/Models/Feed.php+./app/Models/FeedDAO.php+./app/Models/FeedDAOSQLite.php+./app/Models/FilterAction.php+./app/Models/FormAuth.php+./app/Models/Log.php+./app/Models/ReadingMode.php+./app/Models/Search.php+./app/Models/Share.php+./app/Models/TagDAO.php+./app/Models/TagDAOSQLite.php+./app/Models/Themes.php+./app/Models/UserDAO.php+./app/Models/View.php+./app/Services/ExportService.php+./app/Services/ImportService.php+./cli/_cli.php+./cli/_update-or-create-user.php+./cli/check.translation.php+./cli/i18n/I18nCompletionValidator.php+./cli/i18n/I18nData.php+./cli/i18n/I18nFile.php+./cli/i18n/I18nUsageValidator.php+./cli/i18n/I18nValidatorInterface.php+./cli/i18n/I18nValue.php+./cli/manipulate.translation.php+./lib/core-extensions/Google-Groups/extension.php+./lib/core-extensions/Tumblr-GDPR/extension.php+./lib/favicons.php+./lib/http-conditional.php+./lib/lib_date.php+./lib/lib_install.php+./lib/Minz/ActionController.php+./lib/Minz/ActionException.php+./lib/Minz/Configuration.php+./lib/Minz/ConfigurationException.php+./lib/Minz/ControllerNotActionControllerException.php+./lib/Minz/ControllerNotExistException.php+./lib/Minz/CurrentPagePaginationException.php+./lib/Minz/Dispatcher.php+./lib/Minz/Error.php+./lib/Minz/Exception.php+./lib/Minz/Extension.php+./lib/Minz/ExtensionException.php+./lib/Minz/ExtensionManager.php+./lib/Minz/FileNotExistException.php+./lib/Minz/FrontController.php+./lib/Minz/Helper.php+./lib/Minz/Log.php+./lib/Minz/Mailer.php+./lib/Minz/Migrator.php+./lib/Minz/ModelArray.php+./lib/Minz/ModelPdo.php+./lib/Minz/Paginator.php+./lib/Minz/Pdo.php+./lib/Minz/PDOConnectionException.php+./lib/Minz/PdoMysql.php+./lib/Minz/PdoPgsql.php+./lib/Minz/PdoSqlite.php+./lib/Minz/PermissionDeniedException.php+./lib/Minz/Request.php+./lib/Minz/Session.php+./lib/Minz/Translate.php+./lib/Minz/Url.php+./lib/Minz/View.php