Skip to content

Commit 566cf37

Browse files
authored
Use new class synopsis generating markup (#11809)
1 parent 585bdf2 commit 566cf37

File tree

1 file changed

+52
-31
lines changed

1 file changed

+52
-31
lines changed

build/gen_stub.php

Lines changed: 52 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2735,27 +2735,15 @@ public function getClassSynopsisDocument(array $classMap, iterable $allConstInfo
27352735
public function getClassSynopsisElement(DOMDocument $doc, array $classMap, iterable $allConstInfos): ?DOMElement {
27362736

27372737
$classSynopsis = $doc->createElement("classsynopsis");
2738-
if ($this->type === "interface") {
2739-
$classSynopsis->setAttribute("class", "interface");
2740-
}
2741-
$classSynopsis->appendChild(new DOMText("\n "));
2738+
$classSynopsis->setAttribute("class", $this->type === "interface" ? "interface" : "class");
27422739

2743-
$ooElement = self::createOoElement($doc, $this, true, false, false, 4);
2740+
$exceptionOverride = $this->isException($classMap) ? "exception" : null;
2741+
$ooElement = self::createOoElement($doc, $this, $exceptionOverride, true, null, 4);
27442742
if (!$ooElement) {
27452743
return null;
27462744
}
2745+
$classSynopsis->appendChild(new DOMText("\n "));
27472746
$classSynopsis->appendChild($ooElement);
2748-
$classSynopsis->appendChild(new DOMText("\n\n "));
2749-
2750-
$classSynopsisInfo = $doc->createElement("classsynopsisinfo");
2751-
$classSynopsisInfo->appendChild(new DOMText("\n "));
2752-
$ooElement = self::createOoElement($doc, $this, false, true, false, 5);
2753-
if (!$ooElement) {
2754-
return null;
2755-
}
2756-
$classSynopsisInfo->appendChild($ooElement);
2757-
2758-
$classSynopsis->appendChild($classSynopsisInfo);
27592747

27602748
foreach ($this->extends as $k => $parent) {
27612749
$parentInfo = $classMap[$parent->toString()] ?? null;
@@ -2766,33 +2754,32 @@ public function getClassSynopsisElement(DOMDocument $doc, array $classMap, itera
27662754
$ooElement = self::createOoElement(
27672755
$doc,
27682756
$parentInfo,
2757+
null,
27692758
false,
2770-
false,
2771-
$k === 0 && $this->type === "class",
2772-
5
2759+
$k === 0 ? "extends" : null,
2760+
4
27732761
);
27742762
if (!$ooElement) {
27752763
return null;
27762764
}
27772765

2778-
$classSynopsisInfo->appendChild(new DOMText("\n\n "));
2779-
$classSynopsisInfo->appendChild($ooElement);
2766+
$classSynopsis->appendChild(new DOMText("\n\n "));
2767+
$classSynopsis->appendChild($ooElement);
27802768
}
27812769

2782-
foreach ($this->implements as $interface) {
2770+
foreach ($this->implements as $k => $interface) {
27832771
$interfaceInfo = $classMap[$interface->toString()] ?? null;
27842772
if (!$interfaceInfo) {
27852773
throw new Exception("Missing implemented interface " . $interface->toString());
27862774
}
27872775

2788-
$ooElement = self::createOoElement($doc, $interfaceInfo, false, false, false, 5);
2776+
$ooElement = self::createOoElement($doc, $interfaceInfo, null, false, $k === 0 ? "implements" : null, 4);
27892777
if (!$ooElement) {
27902778
return null;
27912779
}
2792-
$classSynopsisInfo->appendChild(new DOMText("\n\n "));
2793-
$classSynopsisInfo->appendChild($ooElement);
2780+
$classSynopsis->appendChild(new DOMText("\n\n "));
2781+
$classSynopsis->appendChild($ooElement);
27942782
}
2795-
$classSynopsisInfo->appendChild(new DOMText("\n "));
27962783

27972784
/** @var array<string, Name> $parentsWithInheritedConstants */
27982785
$parentsWithInheritedConstants = [];
@@ -2921,9 +2908,9 @@ public function getClassSynopsisElement(DOMDocument $doc, array $classMap, itera
29212908
private static function createOoElement(
29222909
DOMDocument $doc,
29232910
ClassInfo $classInfo,
2924-
bool $overrideToClass,
2911+
?string $typeOverride,
29252912
bool $withModifiers,
2926-
bool $isExtends,
2913+
?string $modifierOverride,
29272914
int $indentationLevel
29282915
): ?DOMElement {
29292916
$indentation = str_repeat(" ", $indentationLevel);
@@ -2933,12 +2920,12 @@ private static function createOoElement(
29332920
return null;
29342921
}
29352922

2936-
$type = $overrideToClass ? "class" : $classInfo->type;
2923+
$type = $typeOverride !== null ? $typeOverride : $classInfo->type;
29372924

29382925
$ooElement = $doc->createElement("oo$type");
29392926
$ooElement->appendChild(new DOMText("\n$indentation "));
2940-
if ($isExtends) {
2941-
$ooElement->appendChild($doc->createElement('modifier', 'extends'));
2927+
if ($modifierOverride !== null) {
2928+
$ooElement->appendChild($doc->createElement('modifier', $modifierOverride));
29422929
$ooElement->appendChild(new DOMText("\n$indentation "));
29432930
} elseif ($withModifiers) {
29442931
if ($classInfo->flags & Class_::MODIFIER_FINAL) {
@@ -3046,6 +3033,40 @@ private function collectInheritedMembers(
30463033
}
30473034
}
30483035

3036+
/** @param array<string, ClassInfo> $classMap */
3037+
private function isException(array $classMap): bool
3038+
{
3039+
if ($this->name->toString() === "Throwable") {
3040+
return true;
3041+
}
3042+
3043+
foreach ($this->extends as $parentName) {
3044+
$parent = $classMap[$parentName->toString()] ?? null;
3045+
if ($parent === null) {
3046+
throw new Exception("Missing parent class " . $parentName->toString());
3047+
}
3048+
3049+
if ($parent->isException($classMap)) {
3050+
return true;
3051+
}
3052+
}
3053+
3054+
if ($this->type === "class") {
3055+
foreach ($this->implements as $interfaceName) {
3056+
$interface = $classMap[$interfaceName->toString()] ?? null;
3057+
if ($interface === null) {
3058+
throw new Exception("Missing implemented interface " . $interfaceName->toString());
3059+
}
3060+
3061+
if ($interface->isException($classMap)) {
3062+
return true;
3063+
}
3064+
}
3065+
}
3066+
3067+
return false;
3068+
}
3069+
30493070
private function hasConstructor(): bool
30503071
{
30513072
foreach ($this->funcInfos as $funcInfo) {

0 commit comments

Comments
 (0)