Skip to content

Commit 4a06b57

Browse files
committed
fix: error in rules phpstan
1 parent 87d96e4 commit 4a06b57

File tree

5 files changed

+15
-54
lines changed

5 files changed

+15
-54
lines changed

composer.json

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
"description": "Rector upgrades rules for Codeigniter4",
66
"require": {
77
"php": ">=8.1",
8-
"rector/rector": "^1.0",
9-
"codeigniter/phpstan-codeigniter": "^1.4",
10-
"phpstan/phpstan": "^1.11",
11-
"phpstan/phpstan-strict-rules": "^1.6"
8+
"rector/rector": "^1.1",
9+
"symplify/rule-doc-generator": "^12.1"
1210
},
1311
"require-dev": {
14-
"phpunit/phpunit": "^10.5.16",
15-
"symplify/rule-doc-generator": "^12.1",
16-
"codeigniter/coding-standard": "^1.7"
12+
"codeigniter/coding-standard": "^1.7",
13+
"codeigniter/phpstan-codeigniter": "^1.4",
14+
"ergebnis/composer-normalize": "^2.42",
15+
"phpstan/phpstan": "^1.11",
16+
"phpstan/phpstan-strict-rules": "^1.6",
17+
"phpunit/phpunit": "^10.5.16"
1718
},
1819
"autoload": {
1920
"psr-4": {
@@ -43,6 +44,7 @@
4344
"optimize-autoloader": true,
4445
"sort-packages": true,
4546
"allow-plugins": {
47+
"ergebnis/composer-normalize": true,
4648
"rector/extension-installer": true,
4749
"phpstan/extension-installer": true
4850
}

config/sets/codeigniter45.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,6 @@
8585
VersionCompareFuncCallToConstantRector::class,
8686
]);
8787

88-
$rectorConfig->phpstanConfigs([
89-
'./phpstan.neon.dist',
90-
'./vendor/codeigniter/phpstan-codeigniter/extension.neon',
91-
'./vendor/phpstan/phpstan-strict-rules/rules.neon',
92-
]);
93-
9488
$rectorConfig
9589
->ruleWithConfiguration(StringClassNameToClassConstantRector::class, [
9690
// keep '\\' prefix string on string '\Foo\Bar'

phpstan-baseline.neon

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,11 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: "#^Parameter \\#1 \\$node \\(PhpParser\\\\Node\\\\Expr\\\\FuncCall\\) of method PHPDevsr\\\\Rector\\\\Codeigniter4\\\\Utils\\\\PassStrictParameterToFunctionParameterRector\\:\\:refactor\\(\\) should be contravariant with parameter \\$node \\(PhpParser\\\\Node\\) of method Rector\\\\Contract\\\\Rector\\\\RectorInterface\\:\\:refactor\\(\\)$#"
5-
count: 2
6-
path: src/Utils/PassStrictParameterToFunctionParameterRector.php
7-
8-
-
9-
message: "#^Return type \\(array\\<int, string\\>\\) of method PHPDevsr\\\\Rector\\\\Codeigniter4\\\\Utils\\\\PassStrictParameterToFunctionParameterRector\\:\\:getNodeTypes\\(\\) should be covariant with return type \\(array\\<class\\-string\\<PhpParser\\\\Node\\>\\>\\) of method Rector\\\\Contract\\\\Rector\\\\RectorInterface\\:\\:getNodeTypes\\(\\)$#"
10-
count: 2
11-
path: src/Utils/PassStrictParameterToFunctionParameterRector.php
12-
13-
-
14-
message: "#^Parameter \\#1 \\$node \\(PhpParser\\\\Node\\\\Stmt\\\\TryCatch\\) of method PHPDevsr\\\\Rector\\\\Codeigniter4\\\\Utils\\\\RemoveErrorSuppressInTryCatchStmtsRector\\:\\:refactor\\(\\) should be contravariant with parameter \\$node \\(PhpParser\\\\Node\\) of method Rector\\\\Contract\\\\Rector\\\\RectorInterface\\:\\:refactor\\(\\)$#"
15-
count: 2
16-
path: src/Utils/RemoveErrorSuppressInTryCatchStmtsRector.php
17-
18-
-
19-
message: "#^Return type \\(array\\<int, string\\>\\) of method PHPDevsr\\\\Rector\\\\Codeigniter4\\\\Utils\\\\RemoveErrorSuppressInTryCatchStmtsRector\\:\\:getNodeTypes\\(\\) should be covariant with return type \\(array\\<class\\-string\\<PhpParser\\\\Node\\>\\>\\) of method Rector\\\\Contract\\\\Rector\\\\RectorInterface\\:\\:getNodeTypes\\(\\)$#"
20-
count: 2
21-
path: src/Utils/RemoveErrorSuppressInTryCatchStmtsRector.php
22-
233
-
244
message: "#^Access to an undefined property PhpParser\\\\Node\\\\FunctionLike\\:\\:\\$params\\.$#"
255
count: 2
266
path: src/Utils/UnderscoreToCamelCaseVariableNameRector.php
277

288
-
29-
message: "#^Parameter \\#1 \\$node \\(PhpParser\\\\Node\\\\Expr\\\\Closure\\|PhpParser\\\\Node\\\\Stmt\\\\ClassMethod\\|PhpParser\\\\Node\\\\Stmt\\\\Function_\\|PhpParser\\\\Node\\\\Stmt\\\\Namespace_\\|Rector\\\\PhpParser\\\\Node\\\\CustomNode\\\\FileWithoutNamespace\\) of method PHPDevsr\\\\Rector\\\\Codeigniter4\\\\Utils\\\\UnderscoreToCamelCaseVariableNameRector\\:\\:refactor\\(\\) should be contravariant with parameter \\$node \\(PhpParser\\\\Node\\) of method Rector\\\\Contract\\\\Rector\\\\RectorInterface\\:\\:refactor\\(\\)$#"
30-
count: 2
31-
path: src/Utils/UnderscoreToCamelCaseVariableNameRector.php
32-
33-
-
34-
message: "#^Return type \\(array\\<int, string\\>\\) of method PHPDevsr\\\\Rector\\\\Codeigniter4\\\\Utils\\\\UnderscoreToCamelCaseVariableNameRector\\:\\:getNodeTypes\\(\\) should be covariant with return type \\(array\\<class\\-string\\<PhpParser\\\\Node\\>\\>\\) of method Rector\\\\Contract\\\\Rector\\\\RectorInterface\\:\\:getNodeTypes\\(\\)$#"
35-
count: 2
36-
path: src/Utils/UnderscoreToCamelCaseVariableNameRector.php
37-
38-
-
39-
message: "#^Strict comparison using \\=\\=\\= between string and null will always evaluate to false\\.$#"
9+
message: "#^Binary operation \"\\.\" between '\\$' and PhpParser\\\\Node\\\\Expr\\|string results in an error\\.$#"
4010
count: 1
4111
path: src/Utils/UnderscoreToCamelCaseVariableNameRector.php

phpstan.neon.dist

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ includes:
22
- phpstan-baseline.neon
33

44
parameters:
5-
level: 6
5+
level: 7
66

77
paths:
88
- config
@@ -16,9 +16,3 @@ parameters:
1616

1717
checkMissingCallableSignature: true
1818
treatPhpDocTypesAsCertain: false
19-
strictRules:
20-
allRules: false
21-
disallowedLooseComparison: true
22-
booleansInConditions: true
23-
disallowedConstructs: true
24-
matchingInheritedMethodNames: true

src/Utils/UnderscoreToCamelCaseVariableNameRector.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
use PhpParser\Comment\Doc;
1616
use PhpParser\Node;
17+
use PhpParser\Node\Expr;
1718
use PhpParser\Node\Expr\Closure;
1819
use PhpParser\Node\Expr\Variable;
1920
use PhpParser\Node\FunctionLike;
@@ -159,7 +160,7 @@ private function processRenameVariable(Node $node): ?Variable
159160
return $node;
160161
}
161162

162-
private function updateDocblock(string $variableName, string $camelCaseName, ?FunctionLike $functionLike): void
163+
private function updateDocblock(string $variableName, Expr|string $camelCaseName, ?FunctionLike $functionLike): void
163164
{
164165
if ($functionLike === null) {
165166
return;
@@ -171,11 +172,11 @@ private function updateDocblock(string $variableName, string $camelCaseName, ?Fu
171172
}
172173

173174
$docCommentText = $docComment->getText();
174-
if ($docCommentText === null) {
175+
if (! $docCommentText) {
175176
return;
176177
}
177178

178-
if (!preg_match(sprintf(self::PARAM_NAME_REGEX, $variableName), $docCommentText)) {
179+
if (! preg_match(sprintf(self::PARAM_NAME_REGEX, $variableName), $docCommentText)) {
179180
return;
180181
}
181182

0 commit comments

Comments
 (0)