From f3af3f0f3d4da8023c5e918545d47a51afc4b6c1 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Sun, 26 Mar 2023 23:19:41 +0200 Subject: Automated test towards PHPStan level 6 (#5230) * Automated test towards PHPStan level 6 Contributes to https://github.com/FreshRSS/FreshRSS/issues/4112 With this automated tests, files that are passing Level 6 are tested to avoid regressions towards Level 5 (which is the current baseline for the whole code-base) It is included when calling `make test-all` or can be called specifically by `composer run-script phpstan-next` * Test and example with 3 new passing files --- .github/workflows/tests.yml | 3 ++ app/Models/SystemConfiguration.php | 2 +- app/Models/UserConfiguration.php | 3 +- app/actualize_script.php | 2 +- app/views/helpers/export/opml.phtml | 3 +- composer.json | 4 +- tests/phpstan-next.txt | 93 +++++++++++++++++++++++++++++++++++++ 7 files changed, 105 insertions(+), 5 deletions(-) create mode 100644 tests/phpstan-next.txt diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6e1e6b0a6..ce0be20ce 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -49,6 +49,9 @@ jobs: - name: PHPStan run: composer run-script phpstan + - name: PHPStan Next Level + run: composer run-script phpstan-next + # NPM tests - name: Uses Node.js diff --git a/app/Models/SystemConfiguration.php b/app/Models/SystemConfiguration.php index 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.php index 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.php index 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-line if (!COPY_LOG_TO_SYSLOG && SIMPLEPIE_SYSLOG_ENABLED) { diff --git a/app/views/helpers/export/opml.phtml b/app/views/helpers/export/opml.phtml index 64c83c960..64dc18eba 100644 --- a/app/views/helpers/export/opml.phtml +++ b/app/views/helpers/export/opml.phtml @@ -2,8 +2,9 @@ /** * @param array $feeds + * @return array> */ -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.json index 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.txt new file mode 100644 index 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 -- cgit v1.2.3