1
0
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:
Matthew Brown 2019-01-06 10:01:35 -05:00
parent 90e1648d5b
commit cc26ce682e
2 changed files with 31 additions and 1 deletions

View File

@ -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;
}
}

View File

@ -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
*/