A free, self-hostable news aggregator…
PHPStan: finalise strictArrayFilter (#7794)
Alexandre Alapetite62f32ccadff7
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.ymlindex 4517c9505..dd159ff1f 100644--- a/.github/workflows/tests.yml+++ b/.github/workflows/tests.yml@@ -49,8 +49,8 @@ jobs:- name: PHPStanrun: composer run-script phpstan- - name: PHPStan Next- run: composer run-script phpstan-next+ # - name: PHPStan Next+ # run: composer run-script phpstan-next# NPM testsdiff --git a/app/Controllers/configureController.php b/app/Controllers/configureController.phpindex dc5407e99..6c1561d7c 100644--- a/app/Controllers/configureController.php+++ b/app/Controllers/configureController.php@@ -386,7 +386,7 @@ class FreshRSS_configure_Controller extends FreshRSS_ActionController {$this->view->tags = FreshRSS_Context::labels();if (Minz_Request::isPost()) {- $params = array_filter(Minz_Request::paramArray('query'));+ $params = Minz_Request::paramArray('query');$queryParams = [];$name = Minz_Request::paramString('name') ?: _t('conf.query.number', $id + 1);if ('' === $name) {diff --git a/app/Controllers/feedController.php b/app/Controllers/feedController.phpindex 977143882..97d68883c 100755--- a/app/Controllers/feedController.php+++ b/app/Controllers/feedController.php@@ -221,7 +221,7 @@ class FreshRSS_feed_Controller extends FreshRSS_ActionController {}}- $headers = array_filter(array_map('trim', $headers));+ $headers = array_filter($headers, fn(string $header): bool => trim($header) !== '');if (!empty($headers)) {$opts[CURLOPT_HTTPHEADER] = array_merge($headers, $opts[CURLOPT_HTTPHEADER] ?? []);$opts[CURLOPT_HTTPHEADER] = array_unique($opts[CURLOPT_HTTPHEADER]);diff --git a/app/Controllers/subscriptionController.php b/app/Controllers/subscriptionController.phpindex 70065fc26..424b9a776 100644--- a/app/Controllers/subscriptionController.php+++ b/app/Controllers/subscriptionController.php@@ -207,7 +207,7 @@ class FreshRSS_subscription_Controller extends FreshRSS_ActionController {}}- $headers = array_filter(array_map('trim', $headers));+ $headers = array_filter($headers, fn(string $header): bool => trim($header) !== '');if (!empty($headers)) {$opts[CURLOPT_HTTPHEADER] = array_merge($headers, $opts[CURLOPT_HTTPHEADER] ?? []);$opts[CURLOPT_HTTPHEADER] = array_unique($opts[CURLOPT_HTTPHEADER]);@@ -318,7 +318,7 @@ class FreshRSS_subscription_Controller extends FreshRSS_ActionController {}$conditions = Minz_Request::paramTextToArray('path_entries_conditions', plaintext: true);- $conditions = array_filter(array_map('trim', $conditions));+ $conditions = array_filter($conditions, fn(string $condition): bool => trim($condition) !== '');$feed->_attribute('path_entries_conditions', empty($conditions) ? null : $conditions);$feed->_attribute('path_entries_filter', Minz_Request::paramString('path_entries_filter', true));diff --git a/app/Models/Entry.php b/app/Models/Entry.phpindex 7ba0d3793..7254dd513 100644--- a/app/Models/Entry.php+++ b/app/Models/Entry.php@@ -860,7 +860,7 @@ HTML;}$conditions = $feed->attributeArray('path_entries_conditions') ?? [];- $conditions = array_filter(array_map(fn($v) => is_string($v) ? trim($v) : '', $conditions));+ $conditions = array_filter($conditions, fn($v): bool => (is_string($v) ? trim($v) : '') !== '');if (count($conditions) > 0) {$found = false;foreach ($conditions as $condition) {diff --git a/app/Models/UserQuery.php b/app/Models/UserQuery.phpindex 196d0126e..c78eeccd3 100644--- a/app/Models/UserQuery.php+++ b/app/Models/UserQuery.php@@ -124,7 +124,7 @@ class FreshRSS_UserQuery {'shareOpml' => $this->shareOpml,'description' => $this->description,'imageUrl' => $this->imageUrl,- ]);+ ], fn($v): bool => $v !== '' && $v !== 0 && $v !== false);}/**diff --git a/cli/CliOption.php b/cli/CliOption.phpindex e92fbd804..129d0de03 100644--- a/cli/CliOption.php+++ b/cli/CliOption.php@@ -5,6 +5,7 @@ final class CliOption {public const VALUE_NONE = 'none';public const VALUE_REQUIRED = 'required';public const VALUE_OPTIONAL = 'optional';+ /** @var 'none'|'required'|'optional' $valueTaken */private string $valueTaken = self::VALUE_REQUIRED;/** @var array{type:string,isArray:bool} $types */private array $types = ['type' => 'string', 'isArray' => false];@@ -61,6 +62,7 @@ final class CliOption {return $this;}+ /** @return 'none'|'required'|'optional' */public function getValueTaken(): string {return $this->valueTaken;}@@ -94,6 +96,6 @@ final class CliOption {$this->deprecatedAlias,];- return array_filter($aliases);+ return array_filter($aliases, fn(?string $alias): bool => $alias !== null && trim($alias) !== '');}}diff --git a/cli/CliOptionsParser.php b/cli/CliOptionsParser.phpindex e1a697e35..9ef9e9f10 100644--- a/cli/CliOptionsParser.php+++ b/cli/CliOptionsParser.php@@ -216,8 +216,8 @@ abstract class CliOptionsParser {}return [- 'long' => array_filter($long),- 'short' => $short+ 'long' => array_filter($long, fn(string $v): bool => trim($v) !== ''),+ 'short' => $short,];}diff --git a/cli/create-user.php b/cli/create-user.phpindex cbcc89ba4..0276e80b3 100755--- a/cli/create-user.php+++ b/cli/create-user.php@@ -75,7 +75,7 @@ $values = ['max_posts_per_rss' => $cliOptions->maxPostsPerRss ?? null,];-$values = array_filter($values);+$values = array_filter($values, fn($v): bool => $v !== null && $v !== '');$ok = FreshRSS_user_Controller::createUser($username,diff --git a/cli/reconfigure.php b/cli/reconfigure.phpindex ef86516f9..f2c86a8d4 100755--- a/cli/reconfigure.php+++ b/cli/reconfigure.php@@ -113,7 +113,8 @@ foreach ($values as $name => $value) {}}-$db = array_merge(FreshRSS_Context::systemConf()->db, array_filter($dbValues));+$db = array_merge(FreshRSS_Context::systemConf()->db,+ array_filter($dbValues, fn(?string $v): bool => $v !== null && trim($v) !== ''));performRequirementCheck($db['type']);diff --git a/cli/update-user.php b/cli/update-user.phpindex 946f296fa..7e50503b9 100755--- a/cli/update-user.php+++ b/cli/update-user.php@@ -66,7 +66,7 @@ $values = ['max_posts_per_rss' => $cliOptions->maxPostsPerRss ?? null,];-$values = array_filter($values);+$values = array_filter($values, fn($value): bool => $value !== null && $value !== '');$ok = FreshRSS_user_Controller::updateUser($username,diff --git a/composer.json b/composer.jsonindex d2ae986ca..13344713d 100644--- a/composer.json+++ b/composer.json@@ -77,8 +77,7 @@"@phtml-lint","@phpunit","@phpcs",- "@phpstan",- "@phpstan-next"+ "@phpstan"],"fix": ["@translations",diff --git a/lib/Minz/Migrator.php b/lib/Minz/Migrator.phpindex 47df98e7f..c7e8ea15d 100644--- a/lib/Minz/Migrator.php+++ b/lib/Minz/Migrator.php@@ -33,7 +33,7 @@ class Minz_Migratorif ($applied_migrations === false) {return "Cannot open the {$applied_migrations_path} file";}- $applied_migrations = array_filter(explode("\n", $applied_migrations));+ $applied_migrations = array_filter(explode("\n", $applied_migrations), fn(string $migration): bool => trim($migration) !== '');$migration_files = scandir($migrations_path) ?: [];$migration_files = array_filter($migration_files, static function (string $filename) {diff --git a/lib/lib_rss.php b/lib/lib_rss.phpindex 8954f9921..480152400 100644--- a/lib/lib_rss.php+++ b/lib/lib_rss.php@@ -231,8 +231,8 @@ function format_bytes(int $bytes, int $precision = 2, string $system = 'IEC'): sreturn format_number($bytes, $precision);}$bytes = max(intval($bytes), 0);- $pow = $bytes === 0 ? 0 : floor(log($bytes) / log($base));- $pow = min($pow, count($units) - 1);+ $pow = $bytes === 0 ? 0 : (int)floor(log($bytes) / log($base));+ $pow = min(max(0, $pow), count($units) - 1);$bytes /= pow($base, $pow);return format_number($bytes, $precision) . ' ' . $units[$pow];}diff --git a/phpstan-next.neon b/phpstan-next.neonindex ff29085b8..2b287e44c 100644--- a/phpstan-next.neon+++ b/phpstan-next.neon@@ -4,19 +4,7 @@ includes:parameters:level: max- strictRules:- strictArrayFilter: true # TODO pass+ reportPossiblyNonexistentGeneralArrayOffset: false # TODO: pass maybeexcludePaths:analyse:# TODO: Update files below and remove them from this list- - app/Controllers/configureController.php- - app/Controllers/feedController.php- - app/Controllers/subscriptionController.php- - app/Models/Entry.php- - app/Models/UserQuery.php- - cli/CliOption.php- - cli/CliOptionsParser.php- - cli/create-user.php- - cli/reconfigure.php- - cli/update-user.php- - lib/Minz/Migrator.phpdiff --git a/phpstan.dist.neon b/phpstan.dist.neonindex 4235be800..4cde7f8ab 100644--- a/phpstan.dist.neon+++ b/phpstan.dist.neon@@ -41,15 +41,16 @@ parameters:checkMissingOverrideMethodAttribute: truecheckTooWideReturnTypesInProtectedAndPublicMethods: truereportAnyTypeWideningInVarTag: true+ reportPossiblyNonexistentConstantArrayOffset: truetreatPhpDocTypesAsCertain: falsestrictRules:disallowedEmpty: falsedisallowedLooseComparison: falsedisallowedShortTernary: false- strictArrayFilter: false # TODO pass+ strictArrayFilter: trueexceptions:check:- missingCheckedExceptionInThrows: false # TODO pass+ missingCheckedExceptionInThrows: false # TODO pass maybetooWideThrowType: trueimplicitThrows: falsecheckedExceptionClasses: