Skip to content

Commit

Permalink
EnforceNativeReturnTypehintRule: minor cleanup (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
janedbal authored Sep 7, 2023
1 parent b88557b commit 62712f6
Showing 1 changed file with 1 addition and 25 deletions.
26 changes: 1 addition & 25 deletions src/Rule/EnforceNativeReturnTypehintRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
namespace ShipMonk\PHPStan\Rule;

use Generator;
use LogicException;
use PhpParser\Node;
use PhpParser\Node\Stmt\Throw_;
use PHPStan\Analyser\Scope;
use PHPStan\Node\ClosureReturnStatementsNode;
use PHPStan\Node\FunctionReturnStatementsNode;
use PHPStan\Node\MethodReturnStatementsNode;
use PHPStan\Node\ReturnStatementsNode;
use PHPStan\Php\PhpVersion;
use PHPStan\Rules\Rule;
Expand Down Expand Up @@ -74,7 +70,7 @@ public function processNode(Node $node, Scope $scope): array
return [];
}

if ($this->hasNativeReturnTypehint($node)) {
if ($node->hasNativeReturnTypehint()) {
return [];
}

Expand Down Expand Up @@ -202,26 +198,6 @@ private function getTypeOfReturnStatements(ReturnStatementsNode $node): Type
return TypeCombinator::union(...$types);
}

/**
* To be removed once we bump phpstan version to 1.9.5+ (https://github.com/phpstan/phpstan-src/pull/2141)
*/
private function hasNativeReturnTypehint(ReturnStatementsNode $node): bool
{
if ($node instanceof MethodReturnStatementsNode) { // @phpstan-ignore-line ignore bc warning
return $node->hasNativeReturnTypehint();
}

if ($node instanceof FunctionReturnStatementsNode) { // @phpstan-ignore-line ignore bc warning
return $node->hasNativeReturnTypehint();
}

if ($node instanceof ClosureReturnStatementsNode) { // @phpstan-ignore-line ignore bc warning
return $node->getClosureExpr()->returnType !== null;
}

throw new LogicException('Unexpected subtype');
}

private function getPhpDocReturnType(Node $node, Scope $scope): ?Type
{
$docComment = $node->getDocComment();
Expand Down

0 comments on commit 62712f6

Please sign in to comment.