Skip to content

Commit ec285ff

Browse files
committed
Support multiple file-level phpdoc blocks in gen_stub.php
This allows writing the following: /** @generate-class-entries */ /** @generate-legacy-arginfo 80000 */
1 parent 74c887b commit ec285ff

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

build/gen_stub.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4498,21 +4498,22 @@ function handlePreprocessorConditions(array &$conds, Stmt $stmt): ?string {
44984498
return empty($conds) ? null : implode(' && ', $conds);
44994499
}
45004500

4501-
function getFileDocComment(array $stmts): ?DocComment {
4501+
/** @return DocComment[] */
4502+
function getFileDocComments(array $stmts): array {
45024503
if (empty($stmts)) {
4503-
return null;
4504+
return [];
45044505
}
45054506

45064507
$comments = $stmts[0]->getComments();
4507-
if (empty($comments)) {
4508-
return null;
4509-
}
45104508

4511-
if ($comments[0] instanceof DocComment) {
4512-
return $comments[0];
4509+
$result = [];
4510+
foreach ($comments as $comment) {
4511+
if ($comment instanceof DocComment) {
4512+
$result[] = $comment;
4513+
}
45134514
}
45144515

4515-
return null;
4516+
return $result;
45164517
}
45174518

45184519
function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstract $prettyPrinter) {
@@ -4665,9 +4666,9 @@ protected function pName_FullyQualified(Name\FullyQualified $node): string {
46654666
$nodeTraverser->traverse($stmts);
46664667

46674668
$fileInfo = new FileInfo;
4668-
$fileDocComment = getFileDocComment($stmts);
4669-
if ($fileDocComment) {
4670-
$fileTags = parseDocComment($fileDocComment);
4669+
$fileDocComments = getFileDocComments($stmts);
4670+
if ($fileDocComments !== []) {
4671+
$fileTags = parseDocComments($fileDocComments);
46714672
foreach ($fileTags as $tag) {
46724673
if ($tag->name === 'generate-function-entries') {
46734674
$fileInfo->generateFunctionEntries = true;

0 commit comments

Comments
 (0)