From a81df66485ea7c94655d70f322775e84bef871f9 Mon Sep 17 00:00:00 2001 From: Ondrej Mirtes Date: Fri, 5 Jan 2024 16:34:50 +0100 Subject: [PATCH] Simplify TooWideClosureReturnTypehintRule --- .../TooWideArrowFunctionReturnTypehintRule.php | 9 +++++---- .../TooWideClosureReturnTypehintRule.php | 8 ++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Rules/TooWideTypehints/TooWideArrowFunctionReturnTypehintRule.php b/src/Rules/TooWideTypehints/TooWideArrowFunctionReturnTypehintRule.php index 63eb0662e5..cd05aafe84 100644 --- a/src/Rules/TooWideTypehints/TooWideArrowFunctionReturnTypehintRule.php +++ b/src/Rules/TooWideTypehints/TooWideArrowFunctionReturnTypehintRule.php @@ -24,15 +24,16 @@ public function getNodeType(): string public function processNode(Node $node, Scope $scope): array { - $functionReturnType = $scope->getAnonymousFunctionReturnType(); - if ($functionReturnType === null || !$functionReturnType instanceof UnionType) { + $arrowFunction = $node->getOriginalNode(); + if ($arrowFunction->returnType === null) { return []; } - $arrowFunction = $node->getOriginalNode(); - if ($arrowFunction->returnType === null) { + $functionReturnType = $scope->getFunctionType($arrowFunction->returnType, false, false); + if (!$functionReturnType instanceof UnionType) { return []; } + $expr = $arrowFunction->expr; if ($expr instanceof Node\Expr\YieldFrom || $expr instanceof Node\Expr\Yield_) { return []; diff --git a/src/Rules/TooWideTypehints/TooWideClosureReturnTypehintRule.php b/src/Rules/TooWideTypehints/TooWideClosureReturnTypehintRule.php index d5cf38c3ea..33b5d2f14c 100644 --- a/src/Rules/TooWideTypehints/TooWideClosureReturnTypehintRule.php +++ b/src/Rules/TooWideTypehints/TooWideClosureReturnTypehintRule.php @@ -26,13 +26,13 @@ public function getNodeType(): string public function processNode(Node $node, Scope $scope): array { - $closureReturnType = $scope->getAnonymousFunctionReturnType(); - if ($closureReturnType === null || !$closureReturnType instanceof UnionType) { + $closureExpr = $node->getClosureExpr(); + if ($closureExpr->returnType === null) { return []; } - $closureExpr = $node->getClosureExpr(); - if ($closureExpr->returnType === null) { + $closureReturnType = $scope->getFunctionType($closureExpr->returnType, false, false); + if (!$closureReturnType instanceof UnionType) { return []; }