From bbdd20bfd638d5d56d8ce5033214c7e5ce8d1042 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Sat, 1 Dec 2018 15:29:14 -0500 Subject: [PATCH] Fix #490 - warm about unknown @psalm- annotations --- src/Psalm/DocComment.php | 19 +++++++++++++++++++ tests/performance/diff_parse_large_file.php | 2 ++ 2 files changed, 21 insertions(+) diff --git a/src/Psalm/DocComment.php b/src/Psalm/DocComment.php index 7514c2281..6d6cc074a 100644 --- a/src/Psalm/DocComment.php +++ b/src/Psalm/DocComment.php @@ -128,6 +128,25 @@ class DocComment // is one. $docblock = preg_replace('/^\s*\n/', '', $docblock); + foreach ($special as $special_key => $_) { + if (substr($special_key, 0, 6) === 'psalm-') { + $special_key = substr($special_key, 6); + + if (!in_array( + $special_key, + [ + 'return', 'param', 'template', 'var', 'type', + 'assert', 'assert-if-true', 'assert-if-false', 'suppress', + 'ignore-nullable-return', 'override-property-visibility', + 'override-method-visibility', 'seal-properties', 'seal-methods', + 'generator-return', 'ignore-falsable-return', + ] + )) { + throw new DocblockParseException('Unrecognised annotation @psalm-' . $special_key); + } + } + } + return [ 'description' => $docblock, 'specials' => $special, diff --git a/tests/performance/diff_parse_large_file.php b/tests/performance/diff_parse_large_file.php index 82267122d..83ee6d6fc 100644 --- a/tests/performance/diff_parse_large_file.php +++ b/tests/performance/diff_parse_large_file.php @@ -5,6 +5,8 @@ ini_set('html_errors', '1'); ini_set('memory_limit', '-1'); error_reporting(E_ALL); +gc_disable(); + require __DIR__ . '../../../vendor/autoload.php'; $a = file_get_contents(__DIR__ . '/a.test');