From ec285ff669e8a36360d9f7bb84873562968eaf6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1t=C3=A9=20Kocsis?= Date: Tue, 5 Mar 2024 21:24:21 +0100 Subject: [PATCH] Support multiple file-level phpdoc blocks in gen_stub.php This allows writing the following: /** @generate-class-entries */ /** @generate-legacy-arginfo 80000 */ --- build/gen_stub.php | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/build/gen_stub.php b/build/gen_stub.php index 97e404e22a1..4715f7a4013 100755 --- a/build/gen_stub.php +++ b/build/gen_stub.php @@ -4498,21 +4498,22 @@ function handlePreprocessorConditions(array &$conds, Stmt $stmt): ?string { return empty($conds) ? null : implode(' && ', $conds); } -function getFileDocComment(array $stmts): ?DocComment { +/** @return DocComment[] */ +function getFileDocComments(array $stmts): array { if (empty($stmts)) { - return null; + return []; } $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 $comments[0]; - } - - return null; + return $result; } function handleStatements(FileInfo $fileInfo, array $stmts, PrettyPrinterAbstract $prettyPrinter) { @@ -4665,9 +4666,9 @@ function parseStubFile(string $code): FileInfo { $nodeTraverser->traverse($stmts); $fileInfo = new FileInfo; - $fileDocComment = getFileDocComment($stmts); - if ($fileDocComment) { - $fileTags = parseDocComment($fileDocComment); + $fileDocComments = getFileDocComments($stmts); + if ($fileDocComments !== []) { + $fileTags = parseDocComments($fileDocComments); foreach ($fileTags as $tag) { if ($tag->name === 'generate-function-entries') { $fileInfo->generateFunctionEntries = true;