Skip to content

Commit b8ea26b

Browse files
committed
update some for doc parse
1 parent 90340eb commit b8ea26b

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/Util/PhpDoc.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
use function array_merge;
1313
use function in_array;
14-
use function is_array;
1514
use function preg_match;
1615
use function preg_replace;
1716
use function preg_split;
@@ -28,6 +27,17 @@
2827
*/
2928
class PhpDoc
3029
{
30+
/**
31+
* @param string $doc
32+
* @param array $options
33+
*
34+
* @return array
35+
*/
36+
public static function getTags(string $doc, array $options = []): array
37+
{
38+
return self::parseDocs($doc, $options);
39+
}
40+
3141
/**
3242
* 以下三个方法来自 yii2 console/Controller.php 做了一些调整
3343
*/
@@ -46,7 +56,7 @@ class PhpDoc
4656
*
4757
* @return array The parsed tags
4858
*/
49-
public static function getTags(string $comment, array $options = []): array
59+
public static function parseDocs(string $comment, array $options = []): array
5060
{
5161
if (!$comment = trim($comment, "/ \n")) {
5262
return [];
@@ -86,12 +96,11 @@ public static function getTags(string $comment, array $options = []): array
8696
continue;
8797
}
8898

89-
if (!isset($tags[$name])) {
90-
$tags[$name] = trim($matches[2]);
91-
} elseif (is_array($tags[$name])) {
99+
// allow multi tag
100+
if ($multi && in_array($name, $multi, true)) {
92101
$tags[$name][] = trim($matches[2]);
93102
} else {
94-
$tags[$name] = [$tags[$name], trim($matches[2])];
103+
$tags[$name] = trim($matches[2]);
95104
}
96105
}
97106
}

test/Util/PhpDocTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use PHPUnit\Framework\TestCase;
66
use ReflectionMethod;
77
use Toolkit\Stdlib\Util\PhpDoc;
8-
use function vdump;
98

109
/**
1110
* class PhpDocTest

0 commit comments

Comments
 (0)