@@ -122,7 +122,7 @@ public function printClass(ClassType $class, PhpNamespace $namespace = null): st
122122 foreach ($ class ->getProperties () as $ property ) {
123123 $ type = $ property ->getType ();
124124 $ 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) . ' ' )
126126 . '$ ' . $ property ->getName ());
127127
128128 $ properties [] = Helpers::formatDocComment ((string ) $ property ->getComment ())
@@ -248,7 +248,7 @@ protected function printParameters($function, ?PhpNamespace $namespace): string
248248 foreach ($ list as $ param ) {
249249 $ variadic = $ function ->isVariadic () && $ param === end ($ list );
250250 $ type = $ param ->getType ();
251- $ params [] = ( $ type ? ( $ param ->isNullable () ? ' ? ' : '' ) . ( $ this -> resolveTypes && $ namespace ? $ namespace -> unresolveName ( $ type ) : $ type ) . ' ' : ' ' )
251+ $ params [] = ltrim ( $ this -> printType ( $ type, $ param ->isNullable (), $ namespace) . ' ' )
252252 . ($ param ->isReference () ? '& ' : '' )
253253 . ($ variadic ? '... ' : '' )
254254 . '$ ' . $ param ->getName ()
@@ -261,13 +261,21 @@ protected function printParameters($function, ?PhpNamespace $namespace): string
261261 }
262262
263263
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+
264272 /**
265273 * @param Closure|GlobalFunction|Method $function
266274 */
267- protected function printReturnType ($ function , ?PhpNamespace $ namespace ): string
275+ private function printReturnType ($ function , ?PhpNamespace $ namespace ): string
268276 {
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
271279 : '' ;
272280 }
273281}
0 commit comments