diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index 7ac09d1e92..589fd947d2 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -208,7 +208,7 @@ public function __construct( private ScopeContext $context, private PhpVersion $phpVersion, private bool $declareStrictTypes = false, - private FunctionReflection|ExtendedMethodReflection|null $function = null, + private PhpFunctionFromParserNodeReflection|null $function = null, ?string $namespace = null, private array $expressionTypes = [], private array $nativeExpressionTypes = [], @@ -310,9 +310,8 @@ public function getTraitReflection(): ?ClassReflection /** * @api - * @return FunctionReflection|ExtendedMethodReflection|null */ - public function getFunction() + public function getFunction(): ?PhpFunctionFromParserNodeReflection { return $this->function; } diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index 6871211346..c9ae804546 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -728,7 +728,7 @@ private function processStmtNode( $classReflection = $scope->getClassReflection(); $methodReflection = $methodScope->getFunction(); - if (!$methodReflection instanceof ExtendedMethodReflection) { + if (!$methodReflection instanceof PhpMethodFromParserNodeReflection) { throw new ShouldNotHappenException(); } diff --git a/src/Analyser/Scope.php b/src/Analyser/Scope.php index 53ceaa3443..0c1682209d 100644 --- a/src/Analyser/Scope.php +++ b/src/Analyser/Scope.php @@ -16,6 +16,7 @@ use PHPStan\Reflection\NamespaceAnswerer; use PHPStan\Reflection\ParameterReflection; use PHPStan\Reflection\ParametersAcceptor; +use PHPStan\Reflection\Php\PhpFunctionFromParserNodeReflection; use PHPStan\TrinaryLogic; use PHPStan\Type\Type; use PHPStan\Type\TypeWithClassName; @@ -49,10 +50,7 @@ public function isInTrait(): bool; public function getTraitReflection(): ?ClassReflection; - /** - * @return FunctionReflection|ExtendedMethodReflection|null - */ - public function getFunction(); + public function getFunction(): ?PhpFunctionFromParserNodeReflection; public function getFunctionName(): ?string; diff --git a/src/Node/FunctionReturnStatementsNode.php b/src/Node/FunctionReturnStatementsNode.php index 0b065f8a25..4ab53d25c3 100644 --- a/src/Node/FunctionReturnStatementsNode.php +++ b/src/Node/FunctionReturnStatementsNode.php @@ -9,7 +9,7 @@ use PhpParser\NodeAbstract; use PHPStan\Analyser\ImpurePoint; use PHPStan\Analyser\StatementResult; -use PHPStan\Reflection\FunctionReflection; +use PHPStan\Reflection\Php\PhpFunctionFromParserNodeReflection; use function count; /** @@ -32,7 +32,7 @@ public function __construct( private StatementResult $statementResult, private array $executionEnds, private array $impurePoints, - private FunctionReflection $functionReflection, + private PhpFunctionFromParserNodeReflection $functionReflection, ) { parent::__construct($function->getAttributes()); @@ -91,7 +91,7 @@ public function getSubNodeNames(): array return []; } - public function getFunctionReflection(): FunctionReflection + public function getFunctionReflection(): PhpFunctionFromParserNodeReflection { return $this->functionReflection; } diff --git a/src/Node/MethodReturnStatementsNode.php b/src/Node/MethodReturnStatementsNode.php index 0103f58059..96218713d3 100644 --- a/src/Node/MethodReturnStatementsNode.php +++ b/src/Node/MethodReturnStatementsNode.php @@ -10,7 +10,7 @@ use PHPStan\Analyser\ImpurePoint; use PHPStan\Analyser\StatementResult; use PHPStan\Reflection\ClassReflection; -use PHPStan\Reflection\ExtendedMethodReflection; +use PHPStan\Reflection\Php\PhpMethodFromParserNodeReflection; use function count; /** @@ -36,7 +36,7 @@ public function __construct( private array $executionEnds, private array $impurePoints, private ClassReflection $classReflection, - private ExtendedMethodReflection $methodReflection, + private PhpMethodFromParserNodeReflection $methodReflection, ) { parent::__construct($method->getAttributes()); @@ -88,7 +88,7 @@ public function getClassReflection(): ClassReflection return $this->classReflection; } - public function getMethodReflection(): ExtendedMethodReflection + public function getMethodReflection(): PhpMethodFromParserNodeReflection { return $this->methodReflection; } diff --git a/src/Rules/Api/ApiInstanceofRule.php b/src/Rules/Api/ApiInstanceofRule.php index 7882c3473e..db7c28afff 100644 --- a/src/Rules/Api/ApiInstanceofRule.php +++ b/src/Rules/Api/ApiInstanceofRule.php @@ -84,6 +84,9 @@ private function processCoveredClass(Node\Expr\Instanceof_ $node, Scope $scope, if ($classReflection->getName() === Type::class || $classReflection->isSubclassOf(Type::class)) { return []; } + if ($classReflection->isInterface()) { + return []; + } $instanceofType = $scope->getType($node); if ($instanceofType->isTrue()->or($instanceofType->isFalse())->yes()) { diff --git a/src/Rules/Functions/ReturnTypeRule.php b/src/Rules/Functions/ReturnTypeRule.php index 4a02e64989..8d4714f423 100644 --- a/src/Rules/Functions/ReturnTypeRule.php +++ b/src/Rules/Functions/ReturnTypeRule.php @@ -5,9 +5,8 @@ use PhpParser\Node; use PhpParser\Node\Stmt\Return_; use PHPStan\Analyser\Scope; +use PHPStan\Reflection\MethodReflection; use PHPStan\Reflection\ParametersAcceptorSelector; -use PHPStan\Reflection\Php\PhpFunctionFromParserNodeReflection; -use PHPStan\Reflection\Php\PhpMethodFromParserNodeReflection; use PHPStan\Rules\FunctionReturnTypeCheck; use PHPStan\Rules\Rule; use function sprintf; @@ -40,10 +39,7 @@ public function processNode(Node $node, Scope $scope): array } $function = $scope->getFunction(); - if ( - !($function instanceof PhpFunctionFromParserNodeReflection) - || $function instanceof PhpMethodFromParserNodeReflection - ) { + if ($function instanceof MethodReflection) { return []; }