From e5816b4f3138a9bd87116cb224dbeab877654c4a Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Thu, 7 Sep 2023 13:09:15 +0200 Subject: [PATCH] EnforceNativeReturnTypehintRule: minor cleanup --- src/Rule/EnforceNativeReturnTypehintRule.php | 26 +------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/src/Rule/EnforceNativeReturnTypehintRule.php b/src/Rule/EnforceNativeReturnTypehintRule.php index 33a255e..f6e84c7 100644 --- a/src/Rule/EnforceNativeReturnTypehintRule.php +++ b/src/Rule/EnforceNativeReturnTypehintRule.php @@ -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; @@ -74,7 +70,7 @@ public function processNode(Node $node, Scope $scope): array return []; } - if ($this->hasNativeReturnTypehint($node)) { + if ($node->hasNativeReturnTypehint()) { return []; } @@ -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();