Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PHPStan strict rules #50

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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": {
Expand Down
225 changes: 225 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -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\\<int\\> 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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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

6 changes: 5 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ parameters:
paths:
- src
- tests
reportUnmatchedIgnoredErrors: true
checkBenevolentUnionTypes: true
checkUninitializedProperties: true
checkDynamicProperties: true
checkTooWideReturnTypesInProtectedAndPublicMethods: true
checkImplicitMixed: true
Loading