@@ -27,12 +27,16 @@ protected function formatParams(): string
2727 $ params = [];
2828 foreach ($ this ->function ->getParameters () as $ parameter ) {
2929 $ param = '' ;
30- $ type = (string ) $ parameter ->getType ();
30+ $ type = $ parameter ->getType ();
31+ if ($ type instanceof ReflectionType) {
32+ $ typeAllowsNull = $ type ->allowsNull ();
33+ $ type = (string ) $ type ;
34+ } else {
35+ $ type = '' ;
36+ }
3137
3238 if ($ type !== '' ) {
33- if ($ parameter ->allowsNull () &&
34- (!$ parameter ->isDefaultValueAvailable () || $ parameter ->getDefaultValue () !== null )
35- ) {
39+ if ($ typeAllowsNull ) {
3640 $ param .= '? ' ;
3741 }
3842
@@ -73,6 +77,7 @@ protected function formatReturnType(): string
7377
7478 if ($ this ->function ->hasReturnType ()) {
7579 $ returnType = $ this ->function ->getReturnType ();
80+
7681 if ($ returnType instanceof ReflectionType) {
7782 $ allowsNull = $ returnType ->allowsNull ();
7883 $ returnType = (string ) $ returnType ;
@@ -95,11 +100,13 @@ public function format(): string
95100 $ t = PhpStubGenerator::$ tab ;
96101
97102 $ result = '' ;
98- $ result .= FormatHelper::indentDocBlock ((string ) $ this ->function ->getDocComment (), 1 , $ t ) . $ n
99- . $ t ;
103+ $ doc = $ this ->function ->getDocComment ();
104+ if (is_string ($ doc )) {
105+ $ result .= FormatHelper::indentDocBlock ($ doc , 1 , $ t ) . $ n ;
106+ }
100107
101- $ result .= 'function ' . $ this ->function ->getName () . '( ' . $ this ->formatParams () . ') ' ;
102- $ this ->formatReturnType ();
108+ $ result .= $ t . 'function ' . $ this ->function ->getName () . '( ' . $ this ->formatParams () . ') ' ;
109+ $ result .= $ this ->formatReturnType ();
103110
104111 $ result .= ' {} ' . $ n . $ n ;
105112
0 commit comments