diff --git a/src/Psalm/DocComment.php b/src/Psalm/DocComment.php index 0335301a5..4535daa43 100644 --- a/src/Psalm/DocComment.php +++ b/src/Psalm/DocComment.php @@ -128,6 +128,7 @@ class DocComment $special_key, [ 'return', 'param', 'template', 'var', 'type', + 'property', 'method', 'assert', 'assert-if-true', 'assert-if-false', 'suppress', 'ignore-nullable-return', 'override-property-visibility', 'override-method-visibility', 'seal-properties', 'seal-methods', diff --git a/src/Psalm/Internal/Analyzer/CommentAnalyzer.php b/src/Psalm/Internal/Analyzer/CommentAnalyzer.php index 708d38744..113da4ef0 100644 --- a/src/Psalm/Internal/Analyzer/CommentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/CommentAnalyzer.php @@ -613,8 +613,11 @@ class CommentAnalyzer } } - if (isset($comments['specials']['method'])) { - foreach ($comments['specials']['method'] as $method_entry) { + if (isset($comments['specials']['method']) || isset($comments['specials']['psalm-method'])) { + $all_methods = (isset($comments['specials']['method']) ? $comments['specials']['method'] : []) + + (isset($comments['specials']['psalm-method']) ? $comments['specials']['psalm-method'] : []); + + foreach ($all_methods as $method_entry) { $method_entry = preg_replace('/[ \t]+/', ' ', trim($method_entry)); $docblock_lines = []; @@ -714,6 +717,7 @@ class CommentAnalyzer } self::addMagicPropertyToInfo($info, $comments['specials'], 'property'); + self::addMagicPropertyToInfo($info, $comments['specials'], 'psalm-property'); self::addMagicPropertyToInfo($info, $comments['specials'], 'property-read'); self::addMagicPropertyToInfo($info, $comments['specials'], 'property-write'); @@ -723,7 +727,7 @@ class CommentAnalyzer /** * @param ClassLikeDocblockComment $info * @param array> $specials - * @param string $property_tag ('property', 'property-read', or 'property-write') + * @param string $property_tag ('property', 'psalm-property', 'property-read', or 'property-write') * * @throws DocblockParseException * diff --git a/tests/MagicMethodAnnotationTest.php b/tests/MagicMethodAnnotationTest.php index de2936b04..3581710cc 100644 --- a/tests/MagicMethodAnnotationTest.php +++ b/tests/MagicMethodAnnotationTest.php @@ -386,6 +386,26 @@ class MagicMethodAnnotationTest extends TestCase '$d' => 'D', ] ], + 'validSimplePsalmAnnotations' => [ + 'getString(); + $child->setInteger(4);', + 'assertions' => [ + '$a' => 'string', + ], + ], ]; } diff --git a/tests/MagicPropertyTest.php b/tests/MagicPropertyTest.php index faaf1ccfb..e12de67e9 100644 --- a/tests/MagicPropertyTest.php +++ b/tests/MagicPropertyTest.php @@ -405,6 +405,35 @@ class MagicPropertyTest extends TestCase $o->foo = "hello"; }', ], + 'psalmPropertyDocblock' => [ + 'foo = "hello"; + $a->bar = "hello"; // not a property', + ], ]; }