From 133efff2cde05cdf4b1290a4c1c5268df78ab42b Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Wed, 31 Jul 2024 19:53:05 +0200 Subject: [PATCH] Improve PHPStan config --- composer.json | 2 +- module/Core/functions/functions.php | 14 ++++++++++++-- phpstan.neon | 5 +++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index f695b063..cd0addb2 100644 --- a/composer.json +++ b/composer.json @@ -114,7 +114,7 @@ ], "cs": "phpcs -s", "cs:fix": "phpcbf", - "stan": "APP_ENV=test php vendor/bin/phpstan analyse module/*/src module/*/test* module/*/config module/*/migrations config docker/config --level=8", + "stan": "APP_ENV=test php vendor/bin/phpstan analyse", "test": [ "@parallel test:unit test:db", "@parallel test:api test:cli" diff --git a/module/Core/functions/functions.php b/module/Core/functions/functions.php index 720f27c1..160ba35e 100644 --- a/module/Core/functions/functions.php +++ b/module/Core/functions/functions.php @@ -109,7 +109,7 @@ function normalizeLocale(string $locale): string * minimum quality * * @param non-empty-string $acceptLanguage - * @param float<0, 1> $minQuality + * @param float $minQuality * @return iterable; */ function acceptLanguageToLocales(string $acceptLanguage, float $minQuality = 0): iterable @@ -142,21 +142,31 @@ function acceptLanguageToLocales(string $acceptLanguage, float $minQuality = 0): */ function splitLocale(string $locale): array { - return array_pad(explode('-', $locale), length: 2, value: null); + [$lang, $countryCode] = array_pad(explode('-', $locale), length: 2, value: null); + return [$lang, $countryCode]; } +/** + * @param InputFilter $inputFilter + */ function getOptionalIntFromInputFilter(InputFilter $inputFilter, string $fieldName): ?int { $value = $inputFilter->getValue($fieldName); return $value !== null ? (int) $value : null; } +/** + * @param InputFilter $inputFilter + */ function getOptionalBoolFromInputFilter(InputFilter $inputFilter, string $fieldName): ?bool { $value = $inputFilter->getValue($fieldName); return $value !== null ? (bool) $value : null; } +/** + * @param InputFilter $inputFilter + */ function getNonEmptyOptionalValueFromInputFilter(InputFilter $inputFilter, string $fieldName): mixed { $value = $inputFilter->getValue($fieldName); diff --git a/phpstan.neon b/phpstan.neon index 7e21a038..72c5ea6d 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -4,6 +4,11 @@ includes: - vendor/phpstan/phpstan-phpunit/extension.neon - vendor/phpstan/phpstan-phpunit/rules.neon parameters: + level: 8 + paths: + - module + - config + - docker/config symfony: console_application_loader: 'config/cli-app.php' doctrine: