diff --git a/src/Psalm/Checker/CommentChecker.php b/src/Psalm/Checker/CommentChecker.php index e219517d1..893ac33f6 100644 --- a/src/Psalm/Checker/CommentChecker.php +++ b/src/Psalm/Checker/CommentChecker.php @@ -143,6 +143,10 @@ class CommentChecker && !strpos($line_parts[0], '::') && $line_parts[0][0] !== '{' ) { + if ($line_parts[0][0] === '$' && $line_parts[0] !== '$this') { + throw new DocblockParseException('Badly-formatted @param type'); + } + $info->return_type = $line_parts[0]; $line_number = array_keys($return_specials)[0]; @@ -176,6 +180,10 @@ class CommentChecker $line_parts[1] = substr($line_parts[1], 1); } + if ($line_parts[0][0] === '$' && $line_parts[0] !== '$this') { + throw new DocblockParseException('Badly-formatted @param type'); + } + $line_parts[1] = preg_replace('/,$/', '', $line_parts[1]); $info->params[] = [ @@ -290,6 +298,10 @@ class CommentChecker $line_parts[1] = substr($line_parts[1], 1); } + if ($line_parts[0][0] === '$' && $line_parts[0] !== '$this') { + throw new DocblockParseException('Badly-formatted @param type'); + } + $line_parts[1] = preg_replace('/,$/', '', $line_parts[1]); $info->properties[] = [ diff --git a/tests/AnnotationTest.php b/tests/AnnotationTest.php index 7588d3c03..fcc9715ca 100644 --- a/tests/AnnotationTest.php +++ b/tests/AnnotationTest.php @@ -173,6 +173,16 @@ class AnnotationTest extends TestCase public function providerFileCheckerInvalidCodeParse() { return [ + 'invalidReturn' => [ + ' 'InvalidDocblock' + ], 'deprecatedMethodWithCall' => [ '