Skip to content

Commit

Permalink
fix: error in rules phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
ddevsr committed May 21, 2024
1 parent 87d96e4 commit 4a06b57
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 54 deletions.
16 changes: 9 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
"description": "Rector upgrades rules for Codeigniter4",
"require": {
"php": ">=8.1",
"rector/rector": "^1.0",
"codeigniter/phpstan-codeigniter": "^1.4",
"phpstan/phpstan": "^1.11",
"phpstan/phpstan-strict-rules": "^1.6"
"rector/rector": "^1.1",
"symplify/rule-doc-generator": "^12.1"
},
"require-dev": {
"phpunit/phpunit": "^10.5.16",
"symplify/rule-doc-generator": "^12.1",
"codeigniter/coding-standard": "^1.7"
"codeigniter/coding-standard": "^1.7",
"codeigniter/phpstan-codeigniter": "^1.4",
"ergebnis/composer-normalize": "^2.42",
"phpstan/phpstan": "^1.11",
"phpstan/phpstan-strict-rules": "^1.6",
"phpunit/phpunit": "^10.5.16"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -43,6 +44,7 @@
"optimize-autoloader": true,
"sort-packages": true,
"allow-plugins": {
"ergebnis/composer-normalize": true,
"rector/extension-installer": true,
"phpstan/extension-installer": true
}
Expand Down
6 changes: 0 additions & 6 deletions config/sets/codeigniter45.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,6 @@
VersionCompareFuncCallToConstantRector::class,
]);

$rectorConfig->phpstanConfigs([
'./phpstan.neon.dist',
'./vendor/codeigniter/phpstan-codeigniter/extension.neon',
'./vendor/phpstan/phpstan-strict-rules/rules.neon',
]);

$rectorConfig
->ruleWithConfiguration(StringClassNameToClassConstantRector::class, [
// keep '\\' prefix string on string '\Foo\Bar'
Expand Down
32 changes: 1 addition & 31 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,41 +1,11 @@
parameters:
ignoreErrors:
-
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\\(\\)$#"
count: 2
path: src/Utils/PassStrictParameterToFunctionParameterRector.php

-
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\\(\\)$#"
count: 2
path: src/Utils/PassStrictParameterToFunctionParameterRector.php

-
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\\(\\)$#"
count: 2
path: src/Utils/RemoveErrorSuppressInTryCatchStmtsRector.php

-
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\\(\\)$#"
count: 2
path: src/Utils/RemoveErrorSuppressInTryCatchStmtsRector.php

-
message: "#^Access to an undefined property PhpParser\\\\Node\\\\FunctionLike\\:\\:\\$params\\.$#"
count: 2
path: src/Utils/UnderscoreToCamelCaseVariableNameRector.php

-
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\\(\\)$#"
count: 2
path: src/Utils/UnderscoreToCamelCaseVariableNameRector.php

-
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\\(\\)$#"
count: 2
path: src/Utils/UnderscoreToCamelCaseVariableNameRector.php

-
message: "#^Strict comparison using \\=\\=\\= between string and null will always evaluate to false\\.$#"
message: "#^Binary operation \"\\.\" between '\\$' and PhpParser\\\\Node\\\\Expr\\|string results in an error\\.$#"
count: 1
path: src/Utils/UnderscoreToCamelCaseVariableNameRector.php
8 changes: 1 addition & 7 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ includes:
- phpstan-baseline.neon

parameters:
level: 6
level: 7

paths:
- config
Expand All @@ -16,9 +16,3 @@ parameters:

checkMissingCallableSignature: true
treatPhpDocTypesAsCertain: false
strictRules:
allRules: false
disallowedLooseComparison: true
booleansInConditions: true
disallowedConstructs: true
matchingInheritedMethodNames: true
7 changes: 4 additions & 3 deletions src/Utils/UnderscoreToCamelCaseVariableNameRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use PhpParser\Comment\Doc;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\FunctionLike;
Expand Down Expand Up @@ -159,7 +160,7 @@ private function processRenameVariable(Node $node): ?Variable
return $node;
}

private function updateDocblock(string $variableName, string $camelCaseName, ?FunctionLike $functionLike): void
private function updateDocblock(string $variableName, Expr|string $camelCaseName, ?FunctionLike $functionLike): void
{
if ($functionLike === null) {
return;
Expand All @@ -171,11 +172,11 @@ private function updateDocblock(string $variableName, string $camelCaseName, ?Fu
}

$docCommentText = $docComment->getText();
if ($docCommentText === null) {
if (! $docCommentText) {
return;
}

if (!preg_match(sprintf(self::PARAM_NAME_REGEX, $variableName), $docCommentText)) {
if (! preg_match(sprintf(self::PARAM_NAME_REGEX, $variableName), $docCommentText)) {
return;
}

Expand Down

0 comments on commit 4a06b57

Please sign in to comment.