From 20422cf2236120cefa53d0013de87797c095f0ad Mon Sep 17 00:00:00 2001 From: Brown Date: Mon, 3 Jun 2019 15:46:25 -0400 Subject: [PATCH] Fix #1730 - parse `@param * $foo` properly --- .../Internal/Analyzer/CommentAnalyzer.php | 19 ++++++++++++++----- tests/AnnotationTest.php | 8 ++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/Psalm/Internal/Analyzer/CommentAnalyzer.php b/src/Psalm/Internal/Analyzer/CommentAnalyzer.php index ae2372520..9f1297171 100644 --- a/src/Psalm/Internal/Analyzer/CommentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/CommentAnalyzer.php @@ -78,7 +78,10 @@ class CommentAnalyzer $line_parts[0] = str_replace("\n", '', preg_replace('@^[ \t]*\*@m', '', $line_parts[0])); - if ($line_parts[0][0] === '$' && $line_parts[0] !== '$this') { + if ($line_parts[0] === '' + || ($line_parts[0][0] === '$' + && !preg_match('/^\$this(\||$)/', $line_parts[0])) + ) { throw new IncorrectDocblockException('Misplaced variable'); } @@ -304,7 +307,10 @@ class CommentAnalyzer $line_parts[0] = str_replace("\n", '', preg_replace('@^[ \t]*\*@m', '', $line_parts[0])); - if ($line_parts[0][0] === '$' && !preg_match('/^\$this(\||$)/', $line_parts[0])) { + if ($line_parts[0] === '' + || ($line_parts[0][0] === '$' + && !preg_match('/^\$this(\||$)/', $line_parts[0])) + ) { throw new IncorrectDocblockException('Misplaced variable'); } @@ -340,14 +346,17 @@ class CommentAnalyzer $line_parts[1] = substr($line_parts[1], 1); } - if ($line_parts[0][0] === '$' && !preg_match('/^\$this(\||$)/', $line_parts[0])) { + $line_parts[0] = str_replace("\n", '', preg_replace('@^[ \t]*\*@m', '', $line_parts[0])); + + if ($line_parts[0] === '' + || ($line_parts[0][0] === '$' + && !preg_match('/^\$this(\||$)/', $line_parts[0])) + ) { throw new IncorrectDocblockException('Misplaced variable'); } $line_parts[1] = preg_replace('/,$/', '', $line_parts[1]); - $line_parts[0] = str_replace("\n", '', preg_replace('@^[ \t]*\*@m', '', $line_parts[0])); - $info->params_out[] = [ 'name' => trim($line_parts[1]), 'type' => str_replace("\n", '', $line_parts[0]), diff --git a/tests/AnnotationTest.php b/tests/AnnotationTest.php index c2cff3814..077444cf3 100644 --- a/tests/AnnotationTest.php +++ b/tests/AnnotationTest.php @@ -1515,6 +1515,14 @@ class AnnotationTest extends TestCase function foo() {}', 'error_message' => 'InvalidReturnType - src' . DIRECTORY_SEPARATOR . 'somefile.php:2:33', ], + 'invalidParamDocblockAsterisk' => [ + ' 'MissingDocblockType' + ] ]; } }