From 8f541590a843abd0a5271cd9ba4512ab86456259 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Tue, 19 Nov 2024 18:06:32 -0300 Subject: [PATCH] Add PHPStan strict rules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- composer.json | 12 ++- phpstan-baseline.neon | 225 ++++++++++++++++++++++++++++++++++++++++++ phpstan.neon.dist | 6 +- 3 files changed, 239 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 5b3cbc6..6e70241 100644 --- a/composer.json +++ b/composer.json @@ -31,9 +31,13 @@ "symfony/expression-language": "^5.0 || ^6.0 || ^7.0" }, "require-dev": { - "phpunit/phpunit": "^8.5 || ^9.6 || ^10.5", "phpmyadmin/coding-standard": "^3.0.0", - "phpstan/phpstan": "^1.12" + "phpstan/extension-installer": "^1.4", + "phpstan/phpstan": "^1.12", + "phpstan/phpstan-deprecation-rules": "^1.2", + "phpstan/phpstan-phpunit": "^1.4", + "phpstan/phpstan-strict-rules": "^1.6", + "phpunit/phpunit": "^8.5 || ^9.6 || ^10.5" }, "autoload": { "psr-4": { @@ -46,8 +50,10 @@ } }, "config": { + "sort-packages": true, "allow-plugins": { - "dealerdirect/phpcodesniffer-composer-installer": true + "dealerdirect/phpcodesniffer-composer-installer": true, + "phpstan/extension-installer": true } }, "suggest": { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index aaeb8c4..56b0bf1 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,15 +1,110 @@ parameters: ignoreErrors: + - + message: "#^Only booleans are allowed in \\|\\|, mixed given on the right side\\.$#" + count: 1 + path: src/Cache/ApcuCache.php + + - + message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#" + count: 1 + path: src/Loader.php + + - + message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" + count: 2 + path: src/Loader.php + + - + message: "#^Dynamic call to static method PhpMyAdmin\\\\MoTranslator\\\\Loader\\:\\:listLocales\\(\\)\\.$#" + count: 1 + path: src/Loader.php + + - + message: "#^Method PhpMyAdmin\\\\MoTranslator\\\\Loader\\:\\:detectlocale\\(\\) should return string but returns mixed\\.$#" + count: 1 + path: src/Loader.php + - message: "#^Offset 'lang' on array\\{0\\: string, lang\\: non\\-falsy\\-string, 1\\: non\\-falsy\\-string, country\\?\\: string, 2\\?\\: string, charset\\?\\: string, 3\\?\\: string, modifier\\?\\: non\\-empty\\-string, \\.\\.\\.\\} on left side of \\?\\? always exists and is not nullable\\.$#" count: 1 path: src/Loader.php + - + message: "#^Only booleans are allowed in an elseif condition, string\\|null given\\.$#" + count: 2 + path: src/Loader.php + + - + message: "#^Only booleans are allowed in an if condition, int\\|false given\\.$#" + count: 1 + path: src/Loader.php + + - + message: "#^Only booleans are allowed in an if condition, string given\\.$#" + count: 1 + path: src/Loader.php + + - + message: "#^Only booleans are allowed in an if condition, string\\|null given\\.$#" + count: 5 + path: src/Loader.php + + - + message: "#^Casting to int something that's already int\\.$#" + count: 1 + path: src/MoParser.php + + - + message: "#^Method PhpMyAdmin\\\\MoTranslator\\\\StringReader\\:\\:readint\\(\\) should return int but returns mixed\\.$#" + count: 1 + path: src/StringReader.php + + - + message: "#^Method PhpMyAdmin\\\\MoTranslator\\\\StringReader\\:\\:readintarray\\(\\) should return array\\ but returns array\\.$#" + count: 1 + path: src/StringReader.php + - message: "#^Cannot cast mixed to int\\.$#" count: 1 path: src/Translator.php + - + message: "#^Dynamic call to static method PhpMyAdmin\\\\MoTranslator\\\\Translator\\:\\:extractPluralCount\\(\\)\\.$#" + count: 1 + path: src/Translator.php + + - + message: "#^Dynamic call to static method PhpMyAdmin\\\\MoTranslator\\\\Translator\\:\\:extractPluralsForms\\(\\)\\.$#" + count: 1 + path: src/Translator.php + + - + message: "#^Dynamic call to static method PhpMyAdmin\\\\MoTranslator\\\\Translator\\:\\:sanitizePluralExpression\\(\\)\\.$#" + count: 1 + path: src/Translator.php + + - + message: "#^Foreach overwrites \\$header with its value variable\\.$#" + count: 1 + path: src/Translator.php + + - + message: "#^Method PhpMyAdmin\\\\MoTranslator\\\\Translator\\:\\:extractPluralsForms\\(\\) should return string but returns \\(string\\|false\\)\\.$#" + count: 1 + path: src/Translator.php + + - + message: "#^Only numeric types are allowed in \\-, int\\|null given on the left side\\.$#" + count: 1 + path: src/Translator.php + + - + message: "#^Parameter \\#1 \\$str of function ltrim expects string, \\(string\\|false\\) given\\.$#" + count: 1 + path: src/Translator.php + - message: "#^Parameter \\#1 \\$str of function ltrim expects string, string\\|false given\\.$#" count: 1 @@ -20,6 +115,101 @@ parameters: count: 1 path: src/Translator.php + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertFalse\\(\\)\\.$#" + count: 1 + path: tests/Cache/ApcuCacheFactoryTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\)\\.$#" + count: 1 + path: tests/Cache/ApcuCacheFactoryTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" + count: 2 + path: tests/Cache/ApcuCacheFactoryTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:markTestSkipped\\(\\)\\.$#" + count: 1 + path: tests/Cache/ApcuCacheFactoryTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#" + count: 2 + path: tests/Cache/ApcuCacheTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertFalse\\(\\)\\.$#" + count: 4 + path: tests/Cache/ApcuCacheTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" + count: 11 + path: tests/Cache/ApcuCacheTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertTrue\\(\\)\\.$#" + count: 1 + path: tests/Cache/ApcuCacheTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:markTestSkipped\\(\\)\\.$#" + count: 1 + path: tests/Cache/ApcuCacheTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:markTestSkipped\\(\\)\\.$#" + count: 1 + path: tests/Cache/ApcuDisabledTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#" + count: 1 + path: tests/Cache/InMemoryCacheTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertFalse\\(\\)\\.$#" + count: 1 + path: tests/Cache/InMemoryCacheTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" + count: 4 + path: tests/Cache/InMemoryCacheTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertTrue\\(\\)\\.$#" + count: 1 + path: tests/Cache/InMemoryCacheTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#" + count: 9 + path: tests/FunctionsTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#" + count: 13 + path: tests/LoaderTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:isInstanceOf\\(\\)\\.$#" + count: 1 + path: tests/LoaderTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:markTestSkipped\\(\\)\\.$#" + count: 1 + path: tests/LoaderTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\TestCase\\:\\:once\\(\\)\\.$#" + count: 1 + path: tests/LoaderTest.php + - message: "#^Method PhpMyAdmin\\\\MoTranslator\\\\Tests\\\\LoaderTest\\:\\:localeList\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -35,6 +225,11 @@ parameters: count: 1 path: tests/LoaderTest.php + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#" + count: 16 + path: tests/MoFilesTest.php + - message: "#^Method PhpMyAdmin\\\\MoTranslator\\\\Tests\\\\MoFilesTest\\:\\:getFiles\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -55,6 +250,11 @@ parameters: count: 1 path: tests/MoFilesTest.php + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#" + count: 3 + path: tests/PluralFormulaTest.php + - message: "#^Method PhpMyAdmin\\\\MoTranslator\\\\Tests\\\\PluralFormulaTest\\:\\:pluralCounts\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -70,6 +270,11 @@ parameters: count: 1 path: tests/PluralFormulaTest.php + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" + count: 3 + path: tests/PluralTest.php + - message: "#^Method PhpMyAdmin\\\\MoTranslator\\\\Tests\\\\PluralTest\\:\\:dataProviderPluralForms\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 @@ -80,3 +285,23 @@ parameters: count: 1 path: tests/PluralTest.php + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertFileExists\\(\\)\\.$#" + count: 2 + path: tests/StringReaderTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" + count: 2 + path: tests/StringReaderTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#" + count: 6 + path: tests/TranslatorTest.php + + - + message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#" + count: 6 + path: tests/TranslatorTest.php + diff --git a/phpstan.neon.dist b/phpstan.neon.dist index ec02511..83b771a 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -5,4 +5,8 @@ parameters: paths: - src - tests - reportUnmatchedIgnoredErrors: true + checkBenevolentUnionTypes: true + checkUninitializedProperties: true + checkDynamicProperties: true + checkTooWideReturnTypesInProtectedAndPublicMethods: true + checkImplicitMixed: true