From 6ea8ab18422c9a0a67853544f376ee524c037cd7 Mon Sep 17 00:00:00 2001 From: inhere Date: Sun, 3 Feb 2019 00:35:42 +0800 Subject: [PATCH] fix: parse comments tags error --- libs/php-utils/src/PhpDoc.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/libs/php-utils/src/PhpDoc.php b/libs/php-utils/src/PhpDoc.php index 039955e..760d31c 100644 --- a/libs/php-utils/src/PhpDoc.php +++ b/libs/php-utils/src/PhpDoc.php @@ -39,13 +39,9 @@ public static function getTags(string $comment, array $options = []): array 'default' => 'description', // default tag name, first line text will attach to it. ], $options); - $allow = (array)$options['allow']; + $allow = (array)$options['allow']; $ignored = (array)$options['ignore']; - - // always allow default tag - if ($default = (string)$options['default']) { - $allow[] = $default; - } + $default = (string)$options['default']; $comment = \str_replace("\r\n", "\n", $comment); $comment = "@{$default} \n" . @@ -59,11 +55,12 @@ public static function getTags(string $comment, array $options = []): array foreach ($parts as $part) { if (\preg_match('/^(\w+)(.*)/ms', \trim($part), $matches)) { $name = $matches[1]; - if (\in_array($name, $ignored, true)) { + if (!$name || \in_array($name, $ignored, true)) { continue; } - if ($allow && !\in_array($name, $allow, true)) { + // always allow default tag + if ($default !== $name && $allow && !\in_array($name, $allow, true)) { continue; }