Skip to content

Commit a98c0e8

Browse files
committed
refactor: apply phpstan
1 parent 319bb6e commit a98c0e8

File tree

8 files changed

+100
-23
lines changed

8 files changed

+100
-23
lines changed

.lintmdrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"tests/",
88
"vendor/",
99
"vendor-bin/",
10-
"./CHANGELOG.md"
10+
"CHANGELOG.md"
1111
],
1212
"rules": {
1313
"space-around-alphabet": 2,

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -513,9 +513,11 @@ $soar->setSudoPassword('your sudo password'); // Set a sudo password to run the
513513
```
514514
</details>
515515

516-
## Testing
516+
## Composer scripts
517517

518-
```bash
518+
```shell
519+
composer benchmark
520+
composer checks:required
519521
composer test
520522
```
521523

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# total 1 error
2+
3+
parameters:
4+
ignoreErrors:
5+
-
6+
message: '#^Cognitive complexity for "Guanguans\\SoarPHP\\Support\\ComposerScripts\:\:resolveSoarHelp\(\)" is 14, keep it under 8$#'
7+
count: 1
8+
path: ../src/Support/ComposerScripts.php

baselines/loader.neon

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
# total 4 errors
1+
# total 15 errors
22

33
includes:
44
- callable.nonCallable.neon
5+
- complexity.functionLike.neon
56
- disallowed.function.neon
7+
- method.childParameterType.neon
68
- new.static.neon
79
- typePerfect.narrowPublicClassMethodParamType.neon
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# total 10 errors
2+
3+
parameters:
4+
ignoreErrors:
5+
-
6+
message: '#^Parameter \#1 \$offset \(string\) of method Guanguans\\SoarPHP\\Soar\:\:offsetExists\(\) should be contravariant with parameter \$offset \(mixed\) of method ArrayAccess\<mixed,mixed\>\:\:offsetExists\(\)$#'
7+
count: 1
8+
path: ../src/Soar.php
9+
10+
-
11+
message: '#^Parameter \#1 \$offset \(string\) of method Guanguans\\SoarPHP\\Soar\:\:offsetGet\(\) should be contravariant with parameter \$offset \(mixed\) of method ArrayAccess\<mixed,mixed\>\:\:offsetGet\(\)$#'
12+
count: 1
13+
path: ../src/Soar.php
14+
15+
-
16+
message: '#^Parameter \#1 \$offset \(string\) of method Guanguans\\SoarPHP\\Soar\:\:offsetSet\(\) should be contravariant with parameter \$offset \(mixed\) of method ArrayAccess\<mixed,mixed\>\:\:offsetSet\(\)$#'
17+
count: 1
18+
path: ../src/Soar.php
19+
20+
-
21+
message: '#^Parameter \#1 \$offset \(string\) of method Guanguans\\SoarPHP\\Soar\:\:offsetUnset\(\) should be contravariant with parameter \$offset \(mixed\) of method ArrayAccess\<mixed,mixed\>\:\:offsetUnset\(\)$#'
22+
count: 1
23+
path: ../src/Soar.php
24+
25+
-
26+
message: '#^Parameter \#1 \$node \(PhpParser\\Node\\Stmt\\Trait_\) of method Guanguans\\SoarPHP\\Support\\Rectors\\AddDocCommentForHasOptionsRector\:\:refactor\(\) should be contravariant with parameter \$node \(PhpParser\\Node\) of method Rector\\Contract\\Rector\\RectorInterface\:\:refactor\(\)$#'
27+
count: 2
28+
path: ../src/Support/Rectors/AddDocCommentForHasOptionsRector.php
29+
30+
-
31+
message: '#^Parameter \#1 \$node \(PhpParser\\Node\\ArrayItem\) of method Guanguans\\SoarPHP\\Support\\Rectors\\AddDocCommentForSoarOptionsRector\:\:refactor\(\) should be contravariant with parameter \$node \(PhpParser\\Node\) of method Rector\\Contract\\Rector\\RectorInterface\:\:refactor\(\)$#'
32+
count: 2
33+
path: ../src/Support/Rectors/AddDocCommentForSoarOptionsRector.php
34+
35+
-
36+
message: '#^Parameter \#1 \$node \(PhpParser\\Node\\Expr\\Array_\) of method Guanguans\\SoarPHP\\Support\\Rectors\\SimplifyListIndexRector\:\:refactor\(\) should be contravariant with parameter \$node \(PhpParser\\Node\) of method Rector\\Contract\\Rector\\RectorInterface\:\:refactor\(\)$#'
37+
count: 2
38+
path: ../src/Support/Rectors/SimplifyListIndexRector.php

phpstan.neon

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ includes:
1313
# - vendor/ergebnis/phpstan-rules/rules.neon
1414
# - vendor/phpstan/phpstan-strict-rules/rules.neon
1515
# - vendor/roave/no-floaters/rules.neon
16+
# - vendor/shipmonk/dead-code-detector/rules.neon
17+
# - vendor/staabm/phpstan-todo-by/extension.neon
1618

1719
- vendor/symplify/phpstan-rules/config/code-complexity-rules.neon
1820
# - vendor/symplify/phpstan-rules/config/configurable-rules.neon
19-
# - vendor/symplify/phpstan-rules/config/naming-rules.neon
20-
# - vendor/symplify/phpstan-rules/config/static-rules.neon
21+
- vendor/symplify/phpstan-rules/config/naming-rules.neon
22+
- vendor/symplify/phpstan-rules/config/static-rules.neon
2123
# - vendor/symplify/phpstan-rules/config/symplify-rules.neon
2224

2325
# - vendor/symplify/phpstan-rules/config/doctrine-rules.neon
24-
# - vendor/symplify/phpstan-rules/config/phpunit-rules.neon
26+
- vendor/symplify/phpstan-rules/config/phpunit-rules.neon
2527
# - vendor/symplify/phpstan-rules/config/rector-rules.neon
2628
# - vendor/symplify/phpstan-rules/config/symfony-rules.neon
2729

@@ -32,15 +34,29 @@ parameters:
3234
- vendor/composer/InstalledVersions.php
3335
excludePaths:
3436
- tests/Fixtures/
37+
tmpDir: .build/phpstan/
3538
level: max
3639
# level: 10
37-
tmpDir: .build/phpstan
40+
editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%'
3841
# errorFormat: symplify
3942
errorFormat: friendly
4043
friendly:
4144
lineBefore: 3
4245
lineAfter: 3
4346
editorUrl: 'phpstorm://open?file=%%file%%&line=%%line%%'
47+
treatPhpDocTypesAsCertain: false
48+
strictRules:
49+
# https://github.com/phpstan/phpstan-strict-rules
50+
allRules: true
51+
booleansInConditions: false
52+
disallowedShortTernary: false
53+
cognitive_complexity:
54+
class: 42
55+
function: 8
56+
dependency_tree: 150
57+
dependency_tree_types:
58+
# # only these explicit types are checked, nothing else
59+
# - Rector\Contract\Rector\RectorInterface
4460
type_coverage:
4561
declare: 100
4662
param_type: 100
@@ -61,20 +77,32 @@ parameters:
6177
-
6278
function: 'env_explode()'
6379
message: 'use config() instead'
64-
-
65-
function: 'env_getcsv()'
66-
message: 'use config() instead'
6780
ignoreErrors:
68-
- identifier: argument.templateType
6981
# - identifier: cast.string
82+
# - identifier: encapsedStringPart.nonString
83+
# - identifier: logicalAnd.resultUnused
7084
# - identifier: return.void
85+
# - identifier: symplify.noDynamicName
7186
# - identifier: typePerfect.noMixedMethodCaller
87+
- identifier: argument.templateType
7288
- identifier: argument.type
7389
- identifier: binaryOp.invalid
74-
# - identifier: encapsedStringPart.nonString
7590
- identifier: logicalAnd.resultUnused
91+
- identifier: method.dynamicName
7692
- identifier: method.nonObject
7793
- identifier: missingType.generics
7894
- identifier: missingType.iterableValue
7995
- identifier: return.type
96+
- identifier: shipmonk.deadMethod
97+
- identifier: symplify.explicitTraitSuffixName
98+
- identifier: symplify.forbiddenExtendOfNonAbstractClass
99+
- identifier: symplify.forbiddenStaticClassConstFetch
80100
- identifier: symplify.noDynamicName
101+
- identifier: symplify.noReturnSetterMethod
102+
- identifier: symplify.requireExceptionNamespace
103+
-
104+
identifier: symplify.explicitInterfaceSuffixName
105+
path: src/Contracts/
106+
107+
108+

src/Concerns/WithDumpable.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public function dd(mixed ...$args): void
3232

3333
/**
3434
* @noinspection ForgottenDebugOutputInspection
35-
* @noinspection DebugFunctionUsageInspection
3635
*/
3736
public function dump(mixed ...$args): self
3837
{

src/Support/OS.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class OS
2727
private const ARM = 'arm';
2828
private const PPC = 'ppc';
2929
private const X86 = 'x86';
30-
private const RegExARM = '/(aarch*|arm*)/';
31-
private const RegExPPC = '/(ppc*)/';
32-
private const RegExX86 = '/(x86*|i386|i686)/';
30+
private const PATTERN_ARM = '/(aarch*|arm*)/';
31+
private const PATTERN_PPC = '/(ppc*)/';
32+
private const PATTERN_X86 = '/(x86*|i386|i686)/';
3333

3434
public static function isUnix(): bool
3535
{
@@ -48,17 +48,17 @@ public static function isMacOS(): bool
4848

4949
public static function isArm(): bool
5050
{
51-
return (bool) preg_match(self::RegExARM, self::getArch());
51+
return (bool) preg_match(self::PATTERN_ARM, self::getArch());
5252
}
5353

5454
public static function isPPC(): bool
5555
{
56-
return (bool) preg_match(self::RegExPPC, self::getArch());
56+
return (bool) preg_match(self::PATTERN_PPC, self::getArch());
5757
}
5858

5959
public static function isX86(): bool
6060
{
61-
return (bool) preg_match(self::RegExX86, self::getArch());
61+
return (bool) preg_match(self::PATTERN_X86, self::getArch());
6262
}
6363

6464
/**
@@ -69,9 +69,9 @@ public static function getArchEnum(): string
6969
$arch = self::getArch();
7070

7171
return match (1) {
72-
preg_match(self::RegExX86, $arch) => self::X86,
73-
preg_match(self::RegExPPC, $arch) => self::PPC,
74-
preg_match(self::RegExARM, $arch) => self::ARM,
72+
preg_match(self::PATTERN_X86, $arch) => self::X86,
73+
preg_match(self::PATTERN_PPC, $arch) => self::PPC,
74+
preg_match(self::PATTERN_ARM, $arch) => self::ARM,
7575
default => throw new RuntimeException("The [$arch] enum not found."),
7676
};
7777
}

0 commit comments

Comments
 (0)