Skip to content

Commit

Permalink
Merge pull request #9250 from weirdan/dont-crash-on-unknown-exception…
Browse files Browse the repository at this point in the history
…s-in-throws-docblock

Fixes #9248
  • Loading branch information
weirdan committed Feb 9, 2023
2 parents 375e5da + 250d4d5 commit 7ae8f9f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,10 @@ public function analyze(

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;
Expand Down
25 changes: 25 additions & 0 deletions tests/ThrowsAnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -634,4 +634,29 @@ function method(): void

$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);
}
}

0 comments on commit 7ae8f9f

Please sign in to comment.