mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Don’t crash when encountering empty @throws
This commit is contained in:
parent
90e1648d5b
commit
cc26ce682e
@ -386,7 +386,13 @@ class CommentAnalyzer
|
||||
|
||||
if (isset($comments['specials']['throws'])) {
|
||||
foreach ($comments['specials']['throws'] as $throws_entry) {
|
||||
$info->throws[] = preg_split('/[\s]+/', $throws_entry)[0];
|
||||
$throws_class = preg_split('/[\s]+/', $throws_entry)[0];
|
||||
|
||||
if (!$throws_class) {
|
||||
throw new IncorrectDocblockException('Unexpectedly empty @throws');
|
||||
}
|
||||
|
||||
$info->throws[] = $throws_class;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -302,6 +302,30 @@ class ThrowsAnnotationTest extends TestCase
|
||||
$this->analyzeFile('somefile.php', $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Psalm\Exception\CodeException
|
||||
* @expectedExceptionMessage MissingDocblockType
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testEmptyThrows()
|
||||
{
|
||||
Config::getInstance()->check_for_throws_docblock = true;
|
||||
|
||||
$this->addFile(
|
||||
'somefile.php',
|
||||
'<?php
|
||||
/**
|
||||
* @throws
|
||||
*/
|
||||
function foo(int $x, int $y) : int {}'
|
||||
);
|
||||
|
||||
$context = new Context();
|
||||
|
||||
$this->analyzeFile('somefile.php', $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user