Skip to content

Commit d42bac2

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

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
@@ -4528,6 +4528,25 @@ public function getVariableName(): string {
45284528

45294529
return $matches["name"];
45304530
}
4531+
4532+
/** @return DocCommentTag[] */
4533+
public static function parseDocComments(array $comments): array {
4534+
$tags = [];
4535+
foreach ($comments as $comment) {
4536+
if (!($comment instanceof DocComment)) {
4537+
continue;
4538+
}
4539+
$commentText = substr($comment->getText(), 2, -2);
4540+
foreach (explode("\n", $commentText) as $commentLine) {
4541+
$regex = '/^\*\s*@([a-z-]+)(?:\s+(.+))?$/';
4542+
if (preg_match($regex, trim($commentLine), $matches)) {
4543+
$tags[] = new DocCommentTag($matches[1], $matches[2] ?? null);
4544+
}
4545+
}
4546+
}
4547+
4548+
return $tags;
4549+
}
45314550
}
45324551

45334552
// Instances of ExposedDocComment are immutable and do not need to be cloned
@@ -4571,25 +4590,6 @@ public static function extractExposedComment(array $comments): ?ExposedDocCommen
45714590
}
45724591
}
45734592

4574-
/** @return DocCommentTag[] */
4575-
function parseDocComments(array $comments): array {
4576-
$tags = [];
4577-
foreach ($comments as $comment) {
4578-
if (!($comment instanceof DocComment)) {
4579-
continue;
4580-
}
4581-
$commentText = substr($comment->getText(), 2, -2);
4582-
foreach (explode("\n", $commentText) as $commentLine) {
4583-
$regex = '/^\*\s*@([a-z-]+)(?:\s+(.+))?$/';
4584-
if (preg_match($regex, trim($commentLine), $matches)) {
4585-
$tags[] = new DocCommentTag($matches[1], $matches[2] ?? null);
4586-
}
4587-
}
4588-
}
4589-
4590-
return $tags;
4591-
}
4592-
45934593
// Instances of FramelessFunctionInfo are immutable and do not need to be cloned
45944594
// when held by an object that is cloned
45954595
class FramelessFunctionInfo {
@@ -4628,7 +4628,7 @@ function parseFunctionLike(
46284628
$framelessFunctionInfos = [];
46294629

46304630
if ($comments) {
4631-
$tags = parseDocComments($comments);
4631+
$tags = DocCommentTag::parseDocComments($comments);
46324632

46334633
foreach ($tags as $tag) {
46344634
switch ($tag->name) {
@@ -4817,7 +4817,7 @@ function parseConstLike(
48174817
$link = null;
48184818
$isFileCacheAllowed = true;
48194819
if ($comments) {
4820-
$tags = parseDocComments($comments);
4820+
$tags = DocCommentTag::parseDocComments($comments);
48214821
foreach ($tags as $tag) {
48224822
if ($tag->name === 'var') {
48234823
$phpDocType = $tag->getType();
@@ -4891,7 +4891,7 @@ function parseProperty(
48914891
$link = null;
48924892

48934893
if ($comments) {
4894-
$tags = parseDocComments($comments);
4894+
$tags = DocCommentTag::parseDocComments($comments);
48954895
foreach ($tags as $tag) {
48964896
if ($tag->name === 'var') {
48974897
$phpDocType = $tag->getType();
@@ -4962,7 +4962,7 @@ function parseClass(
49624962
$allowsDynamicProperties = false;
49634963

49644964
if ($comments) {
4965-
$tags = parseDocComments($comments);
4965+
$tags = DocCommentTag::parseDocComments($comments);
49664966
foreach ($tags as $tag) {
49674967
if ($tag->name === 'alias') {
49684968
$alias = $tag->getValue();
@@ -5067,7 +5067,7 @@ protected function pName_FullyQualified(Name\FullyQualified $node): string {
50675067
$stmts = $parser->parse($code);
50685068
$nodeTraverser->traverse($stmts);
50695069

5070-
$fileTags = parseDocComments(getFileDocComments($stmts));
5070+
$fileTags = DocCommentTag::parseDocComments(getFileDocComments($stmts));
50715071
$fileInfo = new FileInfo($fileTags);
50725072

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

0 commit comments

Comments
 (0)