diff --git a/composer.json b/composer.json index 3e48097..9bf7a82 100644 --- a/composer.json +++ b/composer.json @@ -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": { @@ -43,6 +44,7 @@ "optimize-autoloader": true, "sort-packages": true, "allow-plugins": { + "ergebnis/composer-normalize": true, "rector/extension-installer": true, "phpstan/extension-installer": true } diff --git a/config/sets/codeigniter45.php b/config/sets/codeigniter45.php index 276d41a..7a5dd0d 100644 --- a/config/sets/codeigniter45.php +++ b/config/sets/codeigniter45.php @@ -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' diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 183457a..f7bdfb8 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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\\\\) of method PHPDevsr\\\\Rector\\\\Codeigniter4\\\\Utils\\\\PassStrictParameterToFunctionParameterRector\\:\\:getNodeTypes\\(\\) should be covariant with return type \\(array\\\\>\\) 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\\\\) of method PHPDevsr\\\\Rector\\\\Codeigniter4\\\\Utils\\\\RemoveErrorSuppressInTryCatchStmtsRector\\:\\:getNodeTypes\\(\\) should be covariant with return type \\(array\\\\>\\) 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\\\\) of method PHPDevsr\\\\Rector\\\\Codeigniter4\\\\Utils\\\\UnderscoreToCamelCaseVariableNameRector\\:\\:getNodeTypes\\(\\) should be covariant with return type \\(array\\\\>\\) 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 diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 80148d8..fba2ff9 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,7 +2,7 @@ includes: - phpstan-baseline.neon parameters: - level: 6 + level: 7 paths: - config @@ -16,9 +16,3 @@ parameters: checkMissingCallableSignature: true treatPhpDocTypesAsCertain: false - strictRules: - allRules: false - disallowedLooseComparison: true - booleansInConditions: true - disallowedConstructs: true - matchingInheritedMethodNames: true diff --git a/src/Utils/UnderscoreToCamelCaseVariableNameRector.php b/src/Utils/UnderscoreToCamelCaseVariableNameRector.php index cdd0012..b7ec6ed 100644 --- a/src/Utils/UnderscoreToCamelCaseVariableNameRector.php +++ b/src/Utils/UnderscoreToCamelCaseVariableNameRector.php @@ -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; @@ -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; @@ -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; }