From 2b4eab909a7481917573e5fa9d4a13e0247e155b Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 20 Nov 2024 17:58:26 +0700 Subject: [PATCH] require dev phpstan webmozart v2 and fix phsptan message return --- composer.json | 1 + phpstan.neon | 4 ---- .../Rector/ConstFetch/DowngradePhp72JsonConstRector.php | 2 +- .../Rector/ConstFetch/DowngradePhp73JsonConstRector.php | 4 ++-- .../MethodCall/DowngradeReflectionGetTypeRector.php | 2 +- .../DowngradeArrayFilterNullableCallbackRector.php | 2 +- .../MethodCall/DowngradeReflectionGetAttributesRector.php | 2 +- .../New_/DowngradeArbitraryExpressionsSupportRector.php | 8 ++++---- .../DowngradeNullsafeToTernaryOperatorRector.php | 2 +- .../NodeFactory/ArrayMergeFromArraySpreadFactory.php | 3 +-- 10 files changed, 13 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index b712cb8d..4f812e76 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,7 @@ "require-dev": { "phpstan/extension-installer": "^1.3", "phpstan/phpstan": "^2.0", + "phpstan/phpstan-webmozart-assert": "^2.0", "phpunit/phpunit": "^10.5", "rector/rector-src": "dev-upgrade-to-php-parser5-and-phpstan-2", "symplify/easy-coding-standard": "^12.3", diff --git a/phpstan.neon b/phpstan.neon index 4e28e2c9..55bbe8f6 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -63,10 +63,6 @@ parameters: # see https://github.com/rectorphp/rector-src/actions/runs/11798721617/job/32865546672?pr=6422#step:5:110 - '#Doing instanceof PHPStan\\Type\\.+ is error\-prone and deprecated#' - # follow parent signature - - - identifier: return.unusedType - # phpstan instanceof - identifier: phpstanApi.instanceofAssumption diff --git a/rules/DowngradePhp72/Rector/ConstFetch/DowngradePhp72JsonConstRector.php b/rules/DowngradePhp72/Rector/ConstFetch/DowngradePhp72JsonConstRector.php index debc526d..ce64c1c9 100644 --- a/rules/DowngradePhp72/Rector/ConstFetch/DowngradePhp72JsonConstRector.php +++ b/rules/DowngradePhp72/Rector/ConstFetch/DowngradePhp72JsonConstRector.php @@ -67,7 +67,7 @@ public function getNodeTypes(): array /** * @param ConstFetch|BitwiseOr|If_ $node */ - public function refactor(Node $node): Expr|If_|null|int + public function refactor(Node $node): Expr|If_|null { if ($node instanceof If_) { return $this->refactorIf($node); diff --git a/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php b/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php index c985a470..660903ab 100644 --- a/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php +++ b/rules/DowngradePhp73/Rector/ConstFetch/DowngradePhp73JsonConstRector.php @@ -102,9 +102,9 @@ public function getNodeTypes(): array /** * @param ConstFetch|BitwiseOr|If_|TryCatch|Expression $node - * @return int|null|Expr|If_|array + * @return null|Expr|If_|array */ - public function refactor(Node $node): int|null|Expr|If_|array + public function refactor(Node $node): null|Expr|If_|array { if ($node instanceof If_) { return $this->refactorIf($node); diff --git a/rules/DowngradePhp74/Rector/MethodCall/DowngradeReflectionGetTypeRector.php b/rules/DowngradePhp74/Rector/MethodCall/DowngradeReflectionGetTypeRector.php index 4add4d57..65dcf3bd 100644 --- a/rules/DowngradePhp74/Rector/MethodCall/DowngradeReflectionGetTypeRector.php +++ b/rules/DowngradePhp74/Rector/MethodCall/DowngradeReflectionGetTypeRector.php @@ -74,7 +74,7 @@ public function getNodeTypes(): array /** * @param MethodCall|Ternary|Instanceof_ $node */ - public function refactor(Node $node): Node|null|int + public function refactor(Node $node): Node|null { if ($node instanceof Instanceof_) { return $this->refactorInstanceof($node); diff --git a/rules/DowngradePhp80/Rector/FuncCall/DowngradeArrayFilterNullableCallbackRector.php b/rules/DowngradePhp80/Rector/FuncCall/DowngradeArrayFilterNullableCallbackRector.php index 08520f11..ac510f59 100644 --- a/rules/DowngradePhp80/Rector/FuncCall/DowngradeArrayFilterNullableCallbackRector.php +++ b/rules/DowngradePhp80/Rector/FuncCall/DowngradeArrayFilterNullableCallbackRector.php @@ -89,7 +89,7 @@ public function getNodeTypes(): array /** * @param FuncCall $node */ - public function refactor(Node $node): FuncCall|Ternary|null + public function refactor(Node $node): FuncCall|null { if (! $this->isName($node, 'array_filter')) { return null; diff --git a/rules/DowngradePhp80/Rector/MethodCall/DowngradeReflectionGetAttributesRector.php b/rules/DowngradePhp80/Rector/MethodCall/DowngradeReflectionGetAttributesRector.php index 8745cda4..5e0ceb8e 100644 --- a/rules/DowngradePhp80/Rector/MethodCall/DowngradeReflectionGetAttributesRector.php +++ b/rules/DowngradePhp80/Rector/MethodCall/DowngradeReflectionGetAttributesRector.php @@ -60,7 +60,7 @@ public function getNodeTypes(): array /** * @param Ternary|MethodCall $node */ - public function refactor(Node $node): Ternary|null|int + public function refactor(Node $node): Ternary|null { if ($node instanceof Ternary) { if ($node->if instanceof Expr diff --git a/rules/DowngradePhp80/Rector/New_/DowngradeArbitraryExpressionsSupportRector.php b/rules/DowngradePhp80/Rector/New_/DowngradeArbitraryExpressionsSupportRector.php index de5e9ca5..aa2d3454 100644 --- a/rules/DowngradePhp80/Rector/New_/DowngradeArbitraryExpressionsSupportRector.php +++ b/rules/DowngradePhp80/Rector/New_/DowngradeArbitraryExpressionsSupportRector.php @@ -70,9 +70,9 @@ public function getNodeTypes(): array /** * @param Expression $node - * @return Node\Stmt[]|null|Expression + * @return Expression[]|null */ - public function refactor(Node $node): array|null|Expression + public function refactor(Node $node): array|null { /** @var Assign[] $assigns */ $assigns = $this->betterNodeFinder->findInstancesOf($node, [Assign::class]); @@ -123,7 +123,7 @@ private function isBetweenParentheses(Node $node): bool /** * @param Assign[] $assigns - * @return Node\Stmt[]|null + * @return Expression[]|null */ private function refactorAssign(array $assigns, Expression $expression): array|null { @@ -167,7 +167,7 @@ private function refactorAssign(array $assigns, Expression $expression): array|n } /** - * @return Node\Stmt[]|null + * @return Expression[]|null */ private function refactorInstanceof(Instanceof_ $instanceof, Expression $expression): ?array { diff --git a/rules/DowngradePhp80/Rector/NullsafeMethodCall/DowngradeNullsafeToTernaryOperatorRector.php b/rules/DowngradePhp80/Rector/NullsafeMethodCall/DowngradeNullsafeToTernaryOperatorRector.php index 24e9e78b..03236ed5 100644 --- a/rules/DowngradePhp80/Rector/NullsafeMethodCall/DowngradeNullsafeToTernaryOperatorRector.php +++ b/rules/DowngradePhp80/Rector/NullsafeMethodCall/DowngradeNullsafeToTernaryOperatorRector.php @@ -61,7 +61,7 @@ public function getNodeTypes(): array /** * @param NullsafeMethodCall|NullsafePropertyFetch $node */ - public function refactor(Node $node): ?Ternary + public function refactor(Node $node): Ternary { $nullsafeVariable = $this->createNullsafeVariable(); diff --git a/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php b/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php index 992d0d87..ce10386a 100644 --- a/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php +++ b/rules/DowngradePhp81/NodeFactory/ArrayMergeFromArraySpreadFactory.php @@ -4,7 +4,6 @@ namespace Rector\DowngradePhp81\NodeFactory; -use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\Array_; @@ -27,7 +26,7 @@ public function __construct( ) { } - public function createFromArray(Array_ $array, MutatingScope $mutatingScope): ?Node + public function createFromArray(Array_ $array, MutatingScope $mutatingScope): FuncCall { $newArrayItems = $this->disolveArrayItems($array); return $this->createArrayMergeFuncCall($newArrayItems, $mutatingScope);