@@ -2735,27 +2735,15 @@ public function getClassSynopsisDocument(array $classMap, iterable $allConstInfo
2735
2735
public function getClassSynopsisElement (DOMDocument $ doc , array $ classMap , iterable $ allConstInfos ): ?DOMElement {
2736
2736
2737
2737
$ 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 " );
2742
2739
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 );
2744
2742
if (!$ ooElement ) {
2745
2743
return null ;
2746
2744
}
2745
+ $ classSynopsis ->appendChild (new DOMText ("\n " ));
2747
2746
$ 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 );
2759
2747
2760
2748
foreach ($ this ->extends as $ k => $ parent ) {
2761
2749
$ parentInfo = $ classMap [$ parent ->toString ()] ?? null ;
@@ -2766,33 +2754,32 @@ public function getClassSynopsisElement(DOMDocument $doc, array $classMap, itera
2766
2754
$ ooElement = self ::createOoElement (
2767
2755
$ doc ,
2768
2756
$ parentInfo ,
2757
+ null ,
2769
2758
false ,
2770
- false ,
2771
- $ k === 0 && $ this ->type === "class " ,
2772
- 5
2759
+ $ k === 0 ? "extends " : null ,
2760
+ 4
2773
2761
);
2774
2762
if (!$ ooElement ) {
2775
2763
return null ;
2776
2764
}
2777
2765
2778
- $ classSynopsisInfo ->appendChild (new DOMText ("\n\n " ));
2779
- $ classSynopsisInfo ->appendChild ($ ooElement );
2766
+ $ classSynopsis ->appendChild (new DOMText ("\n\n " ));
2767
+ $ classSynopsis ->appendChild ($ ooElement );
2780
2768
}
2781
2769
2782
- foreach ($ this ->implements as $ interface ) {
2770
+ foreach ($ this ->implements as $ k => $ interface ) {
2783
2771
$ interfaceInfo = $ classMap [$ interface ->toString ()] ?? null ;
2784
2772
if (!$ interfaceInfo ) {
2785
2773
throw new Exception ("Missing implemented interface " . $ interface ->toString ());
2786
2774
}
2787
2775
2788
- $ ooElement = self ::createOoElement ($ doc , $ interfaceInfo , false , false , false , 5 );
2776
+ $ ooElement = self ::createOoElement ($ doc , $ interfaceInfo , null , false , $ k === 0 ? " implements " : null , 4 );
2789
2777
if (!$ ooElement ) {
2790
2778
return null ;
2791
2779
}
2792
- $ classSynopsisInfo ->appendChild (new DOMText ("\n\n " ));
2793
- $ classSynopsisInfo ->appendChild ($ ooElement );
2780
+ $ classSynopsis ->appendChild (new DOMText ("\n\n " ));
2781
+ $ classSynopsis ->appendChild ($ ooElement );
2794
2782
}
2795
- $ classSynopsisInfo ->appendChild (new DOMText ("\n " ));
2796
2783
2797
2784
/** @var array<string, Name> $parentsWithInheritedConstants */
2798
2785
$ parentsWithInheritedConstants = [];
@@ -2921,9 +2908,9 @@ public function getClassSynopsisElement(DOMDocument $doc, array $classMap, itera
2921
2908
private static function createOoElement (
2922
2909
DOMDocument $ doc ,
2923
2910
ClassInfo $ classInfo ,
2924
- bool $ overrideToClass ,
2911
+ ? string $ typeOverride ,
2925
2912
bool $ withModifiers ,
2926
- bool $ isExtends ,
2913
+ ? string $ modifierOverride ,
2927
2914
int $ indentationLevel
2928
2915
): ?DOMElement {
2929
2916
$ indentation = str_repeat (" " , $ indentationLevel );
@@ -2933,12 +2920,12 @@ private static function createOoElement(
2933
2920
return null ;
2934
2921
}
2935
2922
2936
- $ type = $ overrideToClass ? " class " : $ classInfo ->type ;
2923
+ $ type = $ typeOverride !== null ? $ typeOverride : $ classInfo ->type ;
2937
2924
2938
2925
$ ooElement = $ doc ->createElement ("oo $ type " );
2939
2926
$ 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 ));
2942
2929
$ ooElement ->appendChild (new DOMText ("\n$ indentation " ));
2943
2930
} elseif ($ withModifiers ) {
2944
2931
if ($ classInfo ->flags & Class_::MODIFIER_FINAL ) {
@@ -3046,6 +3033,40 @@ private function collectInheritedMembers(
3046
3033
}
3047
3034
}
3048
3035
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
+
3049
3070
private function hasConstructor (): bool
3050
3071
{
3051
3072
foreach ($ this ->funcInfos as $ funcInfo ) {
0 commit comments