@@ -122,7 +122,7 @@ public function printClass(ClassType $class, PhpNamespace $namespace = null): st
122
122
foreach ($ class ->getProperties () as $ property ) {
123
123
$ type = $ property ->getType ();
124
124
$ def = (($ property ->getVisibility () ?: 'public ' ) . ($ property ->isStatic () ? ' static ' : '' ) . ' '
125
- . ( $ type ? ( $ property ->isNullable () ? ' ? ' : '' ) . ( $ this -> resolveTypes && $ namespace ? $ namespace -> unresolveName ( $ type ) : $ type ) . ' ' : ' ' )
125
+ . ltrim ( $ this -> printType ( $ type, $ property ->isNullable (), $ namespace) . ' ' )
126
126
. '$ ' . $ property ->getName ());
127
127
128
128
$ properties [] = Helpers::formatDocComment ((string ) $ property ->getComment ())
@@ -248,7 +248,7 @@ protected function printParameters($function, ?PhpNamespace $namespace): string
248
248
foreach ($ list as $ param ) {
249
249
$ variadic = $ function ->isVariadic () && $ param === end ($ list );
250
250
$ type = $ param ->getType ();
251
- $ params [] = ( $ type ? ( $ param ->isNullable () ? ' ? ' : '' ) . ( $ this -> resolveTypes && $ namespace ? $ namespace -> unresolveName ( $ type ) : $ type ) . ' ' : ' ' )
251
+ $ params [] = ltrim ( $ this -> printType ( $ type, $ param ->isNullable (), $ namespace) . ' ' )
252
252
. ($ param ->isReference () ? '& ' : '' )
253
253
. ($ variadic ? '... ' : '' )
254
254
. '$ ' . $ param ->getName ()
@@ -261,13 +261,21 @@ protected function printParameters($function, ?PhpNamespace $namespace): string
261
261
}
262
262
263
263
264
+ public function printType (?string $ type , bool $ nullable = false , PhpNamespace $ namespace = null ): string
265
+ {
266
+ return $ type
267
+ ? ($ nullable ? '? ' : '' ) . ($ this ->resolveTypes && $ namespace ? $ namespace ->unresolveName ($ type ) : $ type )
268
+ : '' ;
269
+ }
270
+
271
+
264
272
/**
265
273
* @param Closure|GlobalFunction|Method $function
266
274
*/
267
- protected function printReturnType ($ function , ?PhpNamespace $ namespace ): string
275
+ private function printReturnType ($ function , ?PhpNamespace $ namespace ): string
268
276
{
269
- return $ function ->getReturnType ()
270
- ? ': ' . ( $ function -> isReturnNullable () ? ' ? ' : '' ) . ( $ this -> resolveTypes && $ namespace ? $ namespace -> unresolveName ( $ function -> getReturnType ()) : $ function -> getReturnType ())
277
+ return ( $ tmp = $ this -> printType ( $ function ->getReturnType (), $ function -> isReturnNullable (), $ namespace ) )
278
+ ? ': ' . $ tmp
271
279
: '' ;
272
280
}
273
281
}
0 commit comments