Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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