Skip to content

Commit 194b4df

Browse files
gen_stub: move parseDocComments() into DocCommentTag
Reduce the number of global functions by moving it to static method `DocCommentTag::parseDocComments()`.
1 parent 8abb2d2 commit 194b4df

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

build/gen_stub.php

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4501,6 +4501,25 @@ public function getVariableName(): string {
45014501

45024502
return $matches["name"];
45034503
}
4504+
4505+
/** @return DocCommentTag[] */
4506+
public static function parseDocComments(array $comments): array {
4507+
$tags = [];
4508+
foreach ($comments as $comment) {
4509+
if (!($comment instanceof DocComment)) {
4510+
continue;
4511+
}
4512+
$commentText = substr($comment->getText(), 2, -2);
4513+
foreach (explode("\n", $commentText) as $commentLine) {
4514+
$regex = '/^\*\s*@([a-z-]+)(?:\s+(.+))?$/';
4515+
if (preg_match($regex, trim($commentLine), $matches)) {
4516+
$tags[] = new DocCommentTag($matches[1], $matches[2] ?? null);
4517+
}
4518+
}
4519+
}
4520+
4521+
return $tags;
4522+
}
45044523
}
45054524

45064525
// Instances of ExposedDocComment are immutable and do not need to be cloned
@@ -4544,25 +4563,6 @@ public static function extractExposedComment(array $comments): ?ExposedDocCommen
45444563
}
45454564
}
45464565

4547-
/** @return DocCommentTag[] */
4548-
function parseDocComments(array $comments): array {
4549-
$tags = [];
4550-
foreach ($comments as $comment) {
4551-
if (!($comment instanceof DocComment)) {
4552-
continue;
4553-
}
4554-
$commentText = substr($comment->getText(), 2, -2);
4555-
foreach (explode("\n", $commentText) as $commentLine) {
4556-
$regex = '/^\*\s*@([a-z-]+)(?:\s+(.+))?$/';
4557-
if (preg_match($regex, trim($commentLine), $matches)) {
4558-
$tags[] = new DocCommentTag($matches[1], $matches[2] ?? null);
4559-
}
4560-
}
4561-
}
4562-
4563-
return $tags;
4564-
}
4565-
45664566
// Instances of FramelessFunctionInfo are immutable and do not need to be cloned
45674567
// when held by an object that is cloned
45684568
class FramelessFunctionInfo {
@@ -4601,7 +4601,7 @@ function parseFunctionLike(
46014601
$framelessFunctionInfos = [];
46024602

46034603
if ($comments) {
4604-
$tags = parseDocComments($comments);
4604+
$tags = DocCommentTag::parseDocComments($comments);
46054605

46064606
foreach ($tags as $tag) {
46074607
switch ($tag->name) {
@@ -4790,7 +4790,7 @@ function parseConstLike(
47904790
$link = null;
47914791
$isFileCacheAllowed = true;
47924792
if ($comments) {
4793-
$tags = parseDocComments($comments);
4793+
$tags = DocCommentTag::parseDocComments($comments);
47944794
foreach ($tags as $tag) {
47954795
if ($tag->name === 'var') {
47964796
$phpDocType = $tag->getType();
@@ -4864,7 +4864,7 @@ function parseProperty(
48644864
$link = null;
48654865

48664866
if ($comments) {
4867-
$tags = parseDocComments($comments);
4867+
$tags = DocCommentTag::parseDocComments($comments);
48684868
foreach ($tags as $tag) {
48694869
if ($tag->name === 'var') {
48704870
$phpDocType = $tag->getType();
@@ -4935,7 +4935,7 @@ function parseClass(
49354935
$allowsDynamicProperties = false;
49364936

49374937
if ($comments) {
4938-
$tags = parseDocComments($comments);
4938+
$tags = DocCommentTag::parseDocComments($comments);
49394939
foreach ($tags as $tag) {
49404940
if ($tag->name === 'alias') {
49414941
$alias = $tag->getValue();
@@ -5040,7 +5040,7 @@ protected function pName_FullyQualified(Name\FullyQualified $node): string {
50405040
$stmts = $parser->parse($code);
50415041
$nodeTraverser->traverse($stmts);
50425042

5043-
$fileTags = parseDocComments(getFileDocComments($stmts));
5043+
$fileTags = DocCommentTag::parseDocComments(getFileDocComments($stmts));
50445044
$fileInfo = new FileInfo($fileTags);
50455045

50465046
$fileInfo->handleStatements($stmts, $prettyPrinter);

0 commit comments

Comments
 (0)