Support multiple file-level phpdoc blocks in gen_stub.php

This allows writing the following:
/** @generate-class-entries */
/** @generate-legacy-arginfo 80000 */
This commit is contained in:
Máté Kocsis 2024-03-05 21:24:21 +01:00
parent 74c887b04e
commit ec285ff669
No known key found for this signature in database
GPG key ID: FD055E41728BF310

View file

@ -4498,21 +4498,22 @@ function handlePreprocessorConditions(array &$conds, Stmt $stmt): ?string {
return empty($conds) ? null : implode(' && ', $conds); return empty($conds) ? null : implode(' && ', $conds);
} }
function getFileDocComment(array $stmts): ?DocComment { /** @return DocComment[] */
function getFileDocComments(array $stmts): array {
if (empty($stmts)) { if (empty($stmts)) {
return null; return [];
} }
$comments = $stmts[0]->getComments(); $comments = $stmts[0]->getComments();
if (empty($comments)) {
return null; $result = [];
foreach ($comments as $comment) {
if ($comment instanceof DocComment) {
$result[] = $comment;
}
} }
if ($comments[0] instanceof DocComment) { return $result;
return $comments[0];
}
return null;
} }
function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstract $prettyPrinter) { function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstract $prettyPrinter) {
@ -4665,9 +4666,9 @@ function parseStubFile(string $code): FileInfo {
$nodeTraverser->traverse($stmts); $nodeTraverser->traverse($stmts);
$fileInfo = new FileInfo; $fileInfo = new FileInfo;
$fileDocComment = getFileDocComment($stmts); $fileDocComments = getFileDocComments($stmts);
if ($fileDocComment) { if ($fileDocComments !== []) {
$fileTags = parseDocComment($fileDocComment); $fileTags = parseDocComments($fileDocComments);
foreach ($fileTags as $tag) { foreach ($fileTags as $tag) {
if ($tag->name === 'generate-function-entries') { if ($tag->name === 'generate-function-entries') {
$fileInfo->generateFunctionEntries = true; $fileInfo->generateFunctionEntries = true;