@@ -4224,6 +4224,29 @@ public function escape(): string {
4224
4224
public function getLength(): int {
4225
4225
return strlen($this->docComment);
4226
4226
}
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
+ }
4227
4250
}
4228
4251
4229
4252
/** @return DocCommentTag[] */
@@ -4451,7 +4474,7 @@ function parseFunctionLike(
4451
4474
$minimumPhpVersionIdCompatibility,
4452
4475
createAttributes($func->attrGroups),
4453
4476
$framelessFunctionInfos,
4454
- createExposedDocComment ($comments)
4477
+ ExposedDocComment::extractExposedComment ($comments)
4455
4478
);
4456
4479
} catch (Exception $e) {
4457
4480
throw new Exception($name . "(): " .$e->getMessage());
@@ -4528,7 +4551,7 @@ function parseConstLike(
4528
4551
$link,
4529
4552
$phpVersionIdMinimumCompatibility,
4530
4553
$attributes,
4531
- createExposedDocComment ($comments),
4554
+ ExposedDocComment::extractExposedComment ($comments),
4532
4555
$isFileCacheAllowed
4533
4556
);
4534
4557
}
@@ -4595,7 +4618,7 @@ function parseProperty(
4595
4618
$link,
4596
4619
$phpVersionIdMinimumCompatibility,
4597
4620
$attributes,
4598
- createExposedDocComment ($comments)
4621
+ ExposedDocComment::extractExposedComment ($comments)
4599
4622
);
4600
4623
}
4601
4624
@@ -4690,7 +4713,7 @@ function parseClass(
4690
4713
$isDeprecated,
4691
4714
$isStrictProperties,
4692
4715
$attributes,
4693
- createExposedDocComment ($comments),
4716
+ ExposedDocComment::extractExposedComment ($comments),
4694
4717
$isNotSerializable,
4695
4718
$extends,
4696
4719
$implements,
@@ -4720,29 +4743,6 @@ function createAttributes(array $attributeGroups): array {
4720
4743
return $attributes;
4721
4744
}
4722
4745
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
-
4746
4746
function handlePreprocessorConditions(array &$conds, Stmt $stmt): ?string {
4747
4747
foreach ($stmt->getComments() as $comment) {
4748
4748
$text = trim($comment->getText());
0 commit comments