diff --git a/src/utils/Utils.php b/src/utils/Utils.php index 6f9500125..d761f772f 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -506,7 +506,7 @@ final class Utils{ if($rawDocComment === false){ //usually empty doc comment, but this is safer and statically analysable return []; } - preg_match_all('/(*ANYCRLF)^[\t ]*(?:\* )?@([a-zA-Z]+)(?:[\t ]+(.+?))?[\t ]*$/m', $rawDocComment, $matches); + preg_match_all('/(*ANYCRLF)^[\t ]*(?:\* )?@([a-zA-Z\-]+)(?:[\t ]+(.+?))?[\t ]*$/m', $rawDocComment, $matches); return array_combine($matches[1], $matches[2]); } diff --git a/tests/phpunit/utils/UtilsTest.php b/tests/phpunit/utils/UtilsTest.php index 80fe84a45..7a8448815 100644 --- a/tests/phpunit/utils/UtilsTest.php +++ b/tests/phpunit/utils/UtilsTest.php @@ -90,6 +90,12 @@ class UtilsTest extends TestCase{ self::assertCount(0, $tags); } + public function testParseDocCommentWithTagsContainingHyphens() : void{ + $tags = Utils::parseDocComment("/** @phpstan-return list */"); + self::assertArrayHasKey("phpstan-return", $tags); + self::assertEquals("list", $tags["phpstan-return"]); + } + public function testNamespacedNiceClosureName() : void{ //be careful with this test. The closure has to be declared on the same line as the assertion. self::assertSame('closure@' . Filesystem::cleanPath(__FILE__) . '#L' . __LINE__, Utils::getNiceClosureName(function() : void{}));