Skip to content

Commit

Permalink
Fix internal error with an unknown interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Aug 12, 2020
1 parent 73f7e73 commit 19fab3f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/Reflection/ClassReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,15 @@ public function isSubclassOf(string $className): bool
}
}

public function implementsInterface(string $className): bool
{
try {
return $this->reflection->implementsInterface($className);
} catch (\ReflectionException $e) {
return false;
}
}

/**
* @return \PHPStan\Reflection\ClassReflection[]
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/Exceptions/CaughtExceptionExistenceRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function processNode(Node $node, Scope $scope): array
}

$classReflection = $this->reflectionProvider->getClass($className);
if (!$classReflection->isInterface() && !$classReflection->getNativeReflection()->implementsInterface(\Throwable::class)) {
if (!$classReflection->isInterface() && !$classReflection->implementsInterface(\Throwable::class)) {
$errors[] = RuleErrorBuilder::message(sprintf('Caught class %s is not an exception.', $classReflection->getDisplayName()))->line($class->getLine())->build();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Type/ObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ protected function checkSubclassAcceptability(string $thatClass): TrinaryLogic

if ($thisReflection->isInterface() && $thatReflection->isInterface()) {
return TrinaryLogic::createFromBoolean(
$thatReflection->getNativeReflection()->implementsInterface($this->className)
$thatReflection->implementsInterface($this->className)
);
}

Expand Down

0 comments on commit 19fab3f

Please sign in to comment.