Skip to content

Commit

Permalink
Make PHPStan stricter
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
  • Loading branch information
MauricioFauth committed Sep 13, 2023
1 parent 0bbf821 commit ad0a108
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 6 deletions.
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@
},
"require-dev": {
"phpmyadmin/coding-standard": "^4.0",
"phpstan/phpstan": "^1.9",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-phpunit": "^1.3",
"phpstan/phpstan-strict-rules": "^1.5",
"phpunit/phpunit": "^10.3",
"psalm/plugin-phpunit": "^0.18.4",
"vimeo/psalm": "^5.6"
Expand All @@ -53,7 +56,8 @@
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true
},
"discard-changes": true,
"sort-packages": true
Expand Down
206 changes: 206 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
parameters:
ignoreErrors:
-
message: "#^Call to function assert\\(\\) with true will always evaluate to true\\.$#"
count: 1
path: src/Cache/ApcuCache.php

-
message: "#^Call to function is_array\\(\\) with array\\<string, string\\> will always evaluate to true\\.$#"
count: 1
path: src/Cache/ApcuCache.php

-
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: "#^Method PhpMyAdmin\\\\MoTranslator\\\\Loader\\:\\:detectlocale\\(\\) should return string but returns mixed\\.$#"
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: "#^Foreach overwrites \\$header with its value variable\\.$#"
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: "#^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: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#"
count: 16
path: tests/MoFilesTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#"
count: 3
path: tests/PluralFormulaTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#"
count: 3
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: 6 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
includes:
- phpstan-baseline.neon
parameters:
level: max
paths:
- src
- tests
checkBenevolentUnionTypes: true
checkImplicitMixed: true
checkTooWideReturnTypesInProtectedAndPublicMethods: true
checkUninitializedProperties: true
reportUnmatchedIgnoredErrors: true
2 changes: 1 addition & 1 deletion src/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public function getTranslator(string $domain = ''): Translator
$base = './';
}

$localeNames = $this->listLocales($this->locale);
$localeNames = self::listLocales($this->locale);

$filename = '';
foreach ($localeNames as $locale) {
Expand Down
6 changes: 3 additions & 3 deletions src/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ private function getPluralForms(): string
if ($this->pluralEquation === null) {
$header = $this->cache->get('');

$expr = $this->extractPluralsForms($header);
$this->pluralEquation = $this->sanitizePluralExpression($expr);
$this->pluralCount = $this->extractPluralCount($expr);
$expr = self::extractPluralsForms($header);
$this->pluralEquation = self::sanitizePluralExpression($expr);
$this->pluralCount = self::extractPluralCount($expr);
}

return $this->pluralEquation;
Expand Down

0 comments on commit ad0a108

Please sign in to comment.