@@ -2700,17 +2700,18 @@ public function getClassSynopsisElement(DOMDocument $doc, array $classMap, itera
2700
2700
}
2701
2701
$ classSynopsisInfo ->appendChild (new DOMText ("\n " ));
2702
2702
2703
- /** @var Name[] $parentsWithInheritedConstants */
2703
+ /** @var array<string, Name> $parentsWithInheritedConstants */
2704
2704
$ parentsWithInheritedConstants = [];
2705
- /** @var Name[] $parentsWithInheritedProperties */
2705
+ /** @var array<string, Name> $parentsWithInheritedProperties */
2706
2706
$ parentsWithInheritedProperties = [];
2707
- /** @var Name[] $parentsWithInheritedMethods */
2707
+ /** @var array<int, array{name: Name, types: int[]}> $parentsWithInheritedMethods */
2708
2708
$ parentsWithInheritedMethods = [];
2709
2709
2710
2710
$ this ->collectInheritedMembers (
2711
2711
$ parentsWithInheritedConstants ,
2712
2712
$ parentsWithInheritedProperties ,
2713
2713
$ parentsWithInheritedMethods ,
2714
+ $ this ->hasConstructor (),
2714
2715
$ classMap
2715
2716
);
2716
2717
@@ -2756,43 +2757,41 @@ public function getClassSynopsisElement(DOMDocument $doc, array $classMap, itera
2756
2757
"&InheritedProperties; "
2757
2758
);
2758
2759
2759
- $ isConcreteClass = ($ this ->type === "class " && !($ this ->flags & Class_::MODIFIER_ABSTRACT ));
2760
-
2761
- if ($ isConcreteClass || !empty ($ this ->funcInfos )) {
2760
+ if (!empty ($ this ->funcInfos )) {
2762
2761
$ classSynopsis ->appendChild (new DOMText ("\n\n " ));
2763
2762
$ classSynopsisInfo = $ doc ->createElement ("classsynopsisinfo " , "&Methods; " );
2764
2763
$ classSynopsisInfo ->setAttribute ("role " , "comment " );
2765
2764
$ classSynopsis ->appendChild ($ classSynopsisInfo );
2766
- }
2767
2765
2768
- $ classReference = self ::getClassSynopsisReference ($ this ->name );
2769
- $ escapedName = addslashes ($ this ->name ->__toString ());
2766
+ $ classReference = self ::getClassSynopsisReference ($ this ->name );
2767
+ $ escapedName = addslashes ($ this ->name ->__toString ());
2770
2768
2771
- if ( $ isConcreteClass || $ this ->hasConstructor ()) {
2772
- $ classSynopsis ->appendChild (new DOMText ("\n " ));
2773
- $ includeElement = $ this ->createIncludeElement (
2774
- $ doc ,
2775
- "xmlns(db=http://docbook.org/ns/docbook) xpointer(id(' $ classReference')/db:refentry/db:refsect1[@role='description']/descendant::db:constructorsynopsis[@role=' $ escapedName']) "
2776
- );
2777
- $ classSynopsis ->appendChild ($ includeElement );
2778
- }
2769
+ if ( $ this ->hasConstructor ()) {
2770
+ $ classSynopsis ->appendChild (new DOMText ("\n " ));
2771
+ $ includeElement = $ this ->createIncludeElement (
2772
+ $ doc ,
2773
+ "xmlns(db=http://docbook.org/ns/docbook) xpointer(id(' $ classReference')/db:refentry/db:refsect1[@role='description']/descendant::db:constructorsynopsis[@role=' $ escapedName']) "
2774
+ );
2775
+ $ classSynopsis ->appendChild ($ includeElement );
2776
+ }
2779
2777
2780
- if ($ this ->hasMethods ()) {
2781
- $ classSynopsis ->appendChild (new DOMText ("\n " ));
2782
- $ includeElement = $ this ->createIncludeElement (
2783
- $ doc ,
2784
- "xmlns(db=http://docbook.org/ns/docbook) xpointer(id(' $ classReference')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[@role=' $ escapedName']) "
2785
- );
2786
- $ classSynopsis ->appendChild ($ includeElement );
2787
- }
2778
+ if ($ this ->hasMethods ()) {
2779
+ $ classSynopsis ->appendChild (new DOMText ("\n " ));
2780
+ $ includeElement = $ this ->createIncludeElement (
2781
+ $ doc ,
2782
+ "xmlns(db=http://docbook.org/ns/docbook) xpointer(id(' $ classReference')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[@role=' $ escapedName']) "
2783
+ );
2784
+ $ classSynopsis ->appendChild ($ includeElement );
2785
+ }
2788
2786
2789
- if ($ this ->hasDestructor ()) {
2790
- $ classSynopsis ->appendChild (new DOMText ("\n " ));
2791
- $ includeElement = $ this ->createIncludeElement (
2792
- $ doc ,
2793
- "xmlns(db=http://docbook.org/ns/docbook) xpointer(id(' $ classReference')/db:refentry/db:refsect1[@role='description']/descendant::db:destructorsynopsis[@role=' $ escapedName']) "
2794
- );
2795
- $ classSynopsis ->appendChild ($ includeElement );
2787
+ if ($ this ->hasDestructor ()) {
2788
+ $ classSynopsis ->appendChild (new DOMText ("\n " ));
2789
+ $ includeElement = $ this ->createIncludeElement (
2790
+ $ doc ,
2791
+ "xmlns(db=http://docbook.org/ns/docbook) xpointer(id(' $ classReference')/db:refentry/db:refsect1[@role='description']/descendant::db:destructorsynopsis[@role=' $ escapedName']) "
2792
+ );
2793
+ $ classSynopsis ->appendChild ($ includeElement );
2794
+ }
2796
2795
}
2797
2796
2798
2797
if (!empty ($ parentsWithInheritedMethods )) {
@@ -2802,14 +2801,21 @@ public function getClassSynopsisElement(DOMDocument $doc, array $classMap, itera
2802
2801
$ classSynopsis ->appendChild ($ classSynopsisInfo );
2803
2802
2804
2803
foreach ($ parentsWithInheritedMethods as $ parent ) {
2805
- $ classSynopsis ->appendChild (new DOMText ("\n " ));
2806
- $ parentReference = self ::getClassSynopsisReference ($ parent );
2807
- $ escapedParentName = addslashes ($ parent ->__toString ());
2808
- $ includeElement = $ this ->createIncludeElement (
2809
- $ doc ,
2810
- "xmlns(db=http://docbook.org/ns/docbook) xpointer(id(' $ parentReference')/db:refentry/db:refsect1[@role='description']/descendant::db:methodsynopsis[@role=' $ escapedParentName']) "
2811
- );
2812
- $ classSynopsis ->appendChild ($ includeElement );
2804
+ $ parentName = $ parent ["name " ];
2805
+ $ parentMethodsynopsisTypes = $ parent ["types " ];
2806
+
2807
+ $ parentReference = self ::getClassSynopsisReference ($ parentName );
2808
+ $ escapedParentName = addslashes ($ parentName ->__toString ());
2809
+
2810
+ foreach ($ parentMethodsynopsisTypes as $ parentMethodsynopsisType ) {
2811
+ $ classSynopsis ->appendChild (new DOMText ("\n " ));
2812
+ $ includeElement = $ this ->createIncludeElement (
2813
+ $ doc ,
2814
+ "xmlns(db=http://docbook.org/ns/docbook) xpointer(id(' $ parentReference')/db:refentry/db:refsect1[@role='description']/descendant::db: {$ parentMethodsynopsisType }[@role=' $ escapedParentName']) "
2815
+ );
2816
+
2817
+ $ classSynopsis ->appendChild ($ includeElement );
2818
+ }
2813
2819
}
2814
2820
}
2815
2821
@@ -2867,39 +2873,54 @@ public static function getClassSynopsisReference(Name $name): string {
2867
2873
}
2868
2874
2869
2875
/**
2870
- * @param Name[] $parentsWithInheritedConstants
2871
- * @param Name[] $parentsWithInheritedProperties
2872
- * @param Name[] $parentsWithInheritedMethods
2876
+ * @param array<string, Name> $parentsWithInheritedConstants
2877
+ * @param array<string, Name> $parentsWithInheritedProperties
2878
+ * @param array<string, array{name: Name, types: int[]}> $parentsWithInheritedMethods
2873
2879
* @param array<string, ClassInfo> $classMap
2874
2880
*/
2875
2881
private function collectInheritedMembers (
2876
2882
array &$ parentsWithInheritedConstants ,
2877
2883
array &$ parentsWithInheritedProperties ,
2878
2884
array &$ parentsWithInheritedMethods ,
2885
+ bool $ hasConstructor ,
2879
2886
array $ classMap
2880
2887
): void {
2881
2888
foreach ($ this ->extends as $ parent ) {
2882
2889
$ parentInfo = $ classMap [$ parent ->toString ()] ?? null ;
2890
+ $ parentName = $ parent ->toString ();
2891
+
2883
2892
if (!$ parentInfo ) {
2884
- throw new Exception ("Missing parent class " . $ parent -> toString () );
2893
+ throw new Exception ("Missing parent class $ parentName " );
2885
2894
}
2886
2895
2887
- if (!empty ($ parentInfo ->constInfos ) && !isset ($ parentsWithInheritedConstants [$ parent ->toString ()])) {
2888
- $ parentsWithInheritedConstants [$ parent ->toString ()] = $ parent ;
2896
+ if (!empty ($ parentInfo ->constInfos ) && !isset ($ parentsWithInheritedConstants [$ parentName ])) {
2897
+ $ parentsWithInheritedConstants [] = $ parent ;
2898
+ }
2899
+
2900
+ if (!empty ($ parentInfo ->propertyInfos ) && !isset ($ parentsWithInheritedProperties [$ parentName ])) {
2901
+ $ parentsWithInheritedProperties [$ parentName ] = $ parent ;
2889
2902
}
2890
2903
2891
- if (!empty ($ parentInfo ->propertyInfos ) && !isset ($ parentsWithInheritedProperties [$ parent ->toString ()])) {
2892
- $ parentsWithInheritedProperties [$ parent ->toString ()] = $ parent ;
2904
+ if (!$ hasConstructor && $ parentInfo ->hasNonPrivateConstructor ()) {
2905
+ $ parentsWithInheritedMethods [$ parentName ]["name " ] = $ parent ;
2906
+ $ parentsWithInheritedMethods [$ parentName ]["types " ][] = "constructorsynopsis " ;
2893
2907
}
2894
2908
2895
- if (!isset ($ parentsWithInheritedMethods [$ parent ->toString ()]) && $ parentInfo ->hasMethods ()) {
2896
- $ parentsWithInheritedMethods [$ parent ->toString ()] = $ parent ;
2909
+ if ($ parentInfo ->hasMethods ()) {
2910
+ $ parentsWithInheritedMethods [$ parentName ]["name " ] = $ parent ;
2911
+ $ parentsWithInheritedMethods [$ parentName ]["types " ][] = "methodsynopsis " ;
2912
+ }
2913
+
2914
+ if ($ parentInfo ->hasDestructor ()) {
2915
+ $ parentsWithInheritedMethods [$ parentName ]["name " ] = $ parent ;
2916
+ $ parentsWithInheritedMethods [$ parentName ]["types " ][] = "destructorsynopsis " ;
2897
2917
}
2898
2918
2899
2919
$ parentInfo ->collectInheritedMembers (
2900
2920
$ parentsWithInheritedConstants ,
2901
2921
$ parentsWithInheritedProperties ,
2902
2922
$ parentsWithInheritedMethods ,
2923
+ $ hasConstructor ,
2903
2924
$ classMap
2904
2925
);
2905
2926
}
@@ -2921,6 +2942,7 @@ private function collectInheritedMembers(
2921
2942
$ parentsWithInheritedConstants ,
2922
2943
$ unusedParentsWithInheritedProperties ,
2923
2944
$ unusedParentsWithInheritedMethods ,
2945
+ $ hasConstructor ,
2924
2946
$ classMap
2925
2947
);
2926
2948
}
@@ -2937,6 +2959,17 @@ private function hasConstructor(): bool
2937
2959
return false ;
2938
2960
}
2939
2961
2962
+ private function hasNonPrivateConstructor (): bool
2963
+ {
2964
+ foreach ($ this ->funcInfos as $ funcInfo ) {
2965
+ if ($ funcInfo ->name ->isConstructor () && !($ funcInfo ->flags & Class_::MODIFIER_PRIVATE )) {
2966
+ return true ;
2967
+ }
2968
+ }
2969
+
2970
+ return false ;
2971
+ }
2972
+
2940
2973
private function hasDestructor (): bool
2941
2974
{
2942
2975
foreach ($ this ->funcInfos as $ funcInfo ) {
@@ -4061,14 +4094,14 @@ static function (FuncInfo $funcInfo) use ($allConstInfos) {
4061
4094
);
4062
4095
}
4063
4096
4064
- /** @param FuncInfo <string, FuncInfo> $funcInfos */
4065
- function generateOptimizerInfo (array $ funcInfos ): string {
4097
+ /** @param array <string, FuncInfo> $funcMap */
4098
+ function generateOptimizerInfo (array $ funcMap ): string {
4066
4099
4067
4100
$ code = "/* This is a generated file, edit the .stub.php files instead. */ \n\n" ;
4068
4101
4069
4102
$ code .= "static const func_info_t func_infos[] = { \n" ;
4070
4103
4071
- $ code .= generateCodeWithConditions ($ funcInfos , "" , static function (FuncInfo $ funcInfo ) {
4104
+ $ code .= generateCodeWithConditions ($ funcMap , "" , static function (FuncInfo $ funcInfo ) {
4072
4105
return $ funcInfo ->getOptimizerInfo ();
4073
4106
});
4074
4107
@@ -4691,7 +4724,6 @@ function initPhpParser() {
4691
4724
4692
4725
foreach ($ fileInfos as $ fileInfo ) {
4693
4726
foreach ($ fileInfo ->getAllFuncInfos () as $ funcInfo ) {
4694
- /** @var FuncInfo $funcInfo */
4695
4727
$ funcMap [$ funcInfo ->name ->__toString ()] = $ funcInfo ;
4696
4728
4697
4729
// TODO: Don't use aliasMap for methodsynopsis?
0 commit comments