Utils: fix parsing of single-line doc comments, closes #3388 (#3469)

* Utils: fix parsing of single-line doc comments, closes #3388

* correctly handle the empty doc-comment case, add another test case

* ignore an extra phpstan bug
This commit is contained in:
Dylan T
2020-05-06 14:17:08 +01:00
committed by GitHub
parent 84932ce908
commit ef97c8f99e
3 changed files with 36 additions and 1 deletions

View File

@ -662,7 +662,11 @@ class Utils{
* @return string[] an array of tagName => tag value. If the tag has no value, an empty string is used as the value.
*/
public static function parseDocComment(string $docComment) : array{
preg_match_all('/(*ANYCRLF)^[\t ]*\* @([a-zA-Z]+)(?:[\t ]+(.+))?[\t ]*$/m', $docComment, $matches);
$rawDocComment = substr($docComment, 3, -2); //remove the opening and closing markers
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);
return array_combine($matches[1], $matches[2]);
}