@@ -4224,6 +4224,29 @@ public function escape(): string {
42244224 public function getLength(): int {
42254225 return strlen($this->docComment);
42264226 }
4227+
4228+ /** @param array<int, DocComment> $comments */
4229+ public static function extractExposedComment(array $comments): ?ExposedDocComment {
4230+ $exposedDocComment = null;
4231+
4232+ foreach ($comments as $comment) {
4233+ $text = $comment->getText();
4234+ $matches = [];
4235+ $pattern = "#^(\s*\/\*\*)(\s*@genstubs-expose-comment-block)(\s*)$#m";
4236+
4237+ if (preg_match($pattern, $text, $matches) !== 1) {
4238+ continue;
4239+ }
4240+
4241+ if ($exposedDocComment !== null) {
4242+ throw new Exception("Only one PHPDoc comment block can be exposed");
4243+ }
4244+
4245+ $exposedDocComment = preg_replace($pattern, '$1$3', $text);
4246+ }
4247+
4248+ return $exposedDocComment ? new ExposedDocComment($exposedDocComment) : null;
4249+ }
42274250}
42284251
42294252/** @return DocCommentTag[] */
@@ -4451,7 +4474,7 @@ function parseFunctionLike(
44514474 $minimumPhpVersionIdCompatibility,
44524475 createAttributes($func->attrGroups),
44534476 $framelessFunctionInfos,
4454- createExposedDocComment ($comments)
4477+ ExposedDocComment::extractExposedComment ($comments)
44554478 );
44564479 } catch (Exception $e) {
44574480 throw new Exception($name . "(): " .$e->getMessage());
@@ -4528,7 +4551,7 @@ function parseConstLike(
45284551 $link,
45294552 $phpVersionIdMinimumCompatibility,
45304553 $attributes,
4531- createExposedDocComment ($comments),
4554+ ExposedDocComment::extractExposedComment ($comments),
45324555 $isFileCacheAllowed
45334556 );
45344557}
@@ -4595,7 +4618,7 @@ function parseProperty(
45954618 $link,
45964619 $phpVersionIdMinimumCompatibility,
45974620 $attributes,
4598- createExposedDocComment ($comments)
4621+ ExposedDocComment::extractExposedComment ($comments)
45994622 );
46004623}
46014624
@@ -4690,7 +4713,7 @@ function parseClass(
46904713 $isDeprecated,
46914714 $isStrictProperties,
46924715 $attributes,
4693- createExposedDocComment ($comments),
4716+ ExposedDocComment::extractExposedComment ($comments),
46944717 $isNotSerializable,
46954718 $extends,
46964719 $implements,
@@ -4720,29 +4743,6 @@ function createAttributes(array $attributeGroups): array {
47204743 return $attributes;
47214744}
47224745
4723- /** @param array<int, DocComment> $comments */
4724- function createExposedDocComment(array $comments): ?ExposedDocComment {
4725- $exposedDocComment = null;
4726-
4727- foreach ($comments as $comment) {
4728- $text = $comment->getText();
4729- $matches = [];
4730- $pattern = "#^(\s*\/\*\*)(\s*@genstubs-expose-comment-block)(\s*)$#m";
4731-
4732- if (preg_match($pattern, $text, $matches) !== 1) {
4733- continue;
4734- }
4735-
4736- if ($exposedDocComment !== null) {
4737- throw new Exception("Only one PHPDoc comment block can be exposed");
4738- }
4739-
4740- $exposedDocComment = preg_replace($pattern, '$1$3', $text);
4741- }
4742-
4743- return $exposedDocComment ? new ExposedDocComment($exposedDocComment) : null;
4744- }
4745-
47464746function handlePreprocessorConditions(array &$conds, Stmt $stmt): ?string {
47474747 foreach ($stmt->getComments() as $comment) {
47484748 $text = trim($comment->getText());
0 commit comments