Skip to content

Commit

Permalink
Simplify TooWideClosureReturnTypehintRule
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jan 5, 2024
1 parent af14d50 commit a81df66
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 [];
}

Expand Down

0 comments on commit a81df66

Please sign in to comment.