1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Don't crash on unknown exceptions in @throws docblock

Fixes vimeo/psalm#9248
This commit is contained in:
Bruce Weirdan 2023-02-09 02:56:01 -04:00
parent 4eacb2f234
commit 250d4d593e
No known key found for this signature in database
GPG Key ID: CFC3AAB181751B0D
2 changed files with 29 additions and 1 deletions

View File

@ -710,7 +710,10 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer
foreach ($storage->throws as $expected_exception => $_) {
if ($expected_exception === $possibly_thrown_exception
|| $codebase->classExtendsOrImplements($possibly_thrown_exception, $expected_exception)
|| (
$codebase->classOrInterfaceExists($possibly_thrown_exception)
&& $codebase->classExtendsOrImplements($possibly_thrown_exception, $expected_exception)
)
) {
$is_expected = true;
break;

View File

@ -634,4 +634,29 @@ class ThrowsAnnotationTest extends TestCase
$this->analyzeFile('somefile.php', $context);
}
public function testUnknownExceptionInThrowsOfACalledMethod(): void
{
$this->expectExceptionMessage('MissingThrowsDocblock');
$this->expectException(CodeException::class);
Config::getInstance()->check_for_throws_docblock = true;
$this->addFile(
'somefile.php',
'<?php
final class Monkey {
/** @throws InvalidArgumentException */
public function spendsItsDay(): void {
$this->havingFun();
}
/** @throws \Monkey\Shit */
private function havingFun(): void {}
}
',
);
$context = new Context();
$this->analyzeFile('somefile.php', $context);
}
}