@@ -267,9 +267,7 @@ public function visitMethod(PhpMethod $method) {
267267
268268 $ this ->writeParameters ($ method ->getParameters ());
269269 $ this ->writer ->write (") " );
270- if ($ this ->returnTypeHints && false === strpos ($ method ->getType (), '| ' )) {
271- $ this ->writer ->write (": {$ method ->getType ()}" );
272- }
270+ $ this ->writeFunctionReturnType ($ method ->getType ());
273271
274272 if ($ method ->isAbstract () || $ method ->getParent () instanceof PhpInterface) {
275273 $ this ->writer ->write ("; \n\n" );
@@ -308,10 +306,8 @@ public function visitFunction(PhpFunction $function) {
308306
309307 $ this ->writer ->write ("function {$ function ->getName ()}( " );
310308 $ this ->writeParameters ($ function ->getParameters ());
311- $ this ->writer ->write (") " );
312- if ($ this ->returnTypeHints && false === strpos ($ function ->getType (), '| ' )) {
313- $ this ->writer ->write (": {$ function ->getType ()}" );
314- }
309+ $ this ->writer ->write (') ' );
310+ $ this ->writeFunctionReturnType ($ function ->getType ());
315311 $ this ->writer ->write (" { \n" )->indent ()->writeln (trim ($ function ->getBody ()))->outdent ()->rtrim ()->write ('} ' );
316312 }
317313
@@ -355,4 +351,10 @@ protected function writeParameters(array $parameters) {
355351 }
356352 }
357353 }
354+
355+ protected function writeFunctionReturnType ($ type ) {
356+ if ($ this ->returnTypeHints && false === strpos ($ type , '| ' )) {
357+ $ this ->writer ->write (': ' )->write ($ type );
358+ }
359+ }
358360}
0 commit comments