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
This commit is contained in:
Alexandre Alapetite 2023-03-26 23:19:41 +02:00 committed by GitHub
parent 05e10f0e75
commit f3af3f0f3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 105 additions and 5 deletions

View File

@ -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

View File

@ -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');
}

View File

@ -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');
}

View File

@ -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) {

View File

@ -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) {

View File

@ -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",

93
tests/phpstan-next.txt Normal file
View File

@ -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