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

Fix notice for certain invalid docblocks (#5709)

Fixes vimeo/psalm#5680
This commit is contained in:
Bruce Weirdan 2021-05-04 05:28:17 +03:00 committed by GitHub
parent 0189420814
commit 27ea40eda0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -59,7 +59,7 @@ class FunctionLikeDocblockParser
if (count($line_parts) > 1) {
if (preg_match('/^&?(\.\.\.)?&?\$[A-Za-z0-9_]+,?$/', $line_parts[1])
&& $line_parts[0][0] !== '{'
&& ($line_parts[0] === '' || $line_parts[0][0] !== '{')
) {
$line_parts[1] = str_replace('&', '', $line_parts[1]);

View File

@ -2,6 +2,7 @@
namespace Psalm\Tests;
use PHPUnit\Framework\TestCase as BaseTestCase;
use Psalm\Exception\IncorrectDocblockException;
use Psalm\Internal\RuntimeCaches;
use Psalm\Internal\PhpVisitor\Reflector\FunctionLikeDocblockParser;
@ -54,4 +55,16 @@ class FunctionLikeDocblockParserTest extends BaseTestCase
$this->assertTrue(isset($function_docblock->params[1]['description']));
$this->assertSame('The blah tags that has a very long multiline description.', $function_docblock->params[1]['description']);
}
public function testMisplacedVariableOnNextLine(): void
{
$doc = '/**
* @param
* $p
*/';
$php_parser_doc = new \PhpParser\Comment\Doc($doc);
$this->expectException(IncorrectDocblockException::class);
$this->expectExceptionMessage('Misplaced variable');
FunctionLikeDocblockParser::parse($php_parser_doc);
}
}