@@ -38,13 +38,16 @@ class Printer
3838
3939 public function printFunction (GlobalFunction $ function , PhpNamespace $ namespace = null ): string
4040 {
41+ $ line = 'function '
42+ . ($ function ->getReturnReference () ? '& ' : '' )
43+ . $ function ->getName ();
44+ $ returnType = $ this ->printReturnType ($ function , $ namespace );
45+
4146 return Helpers::formatDocComment ($ function ->getComment () . "\n" )
4247 . self ::printAttributes ($ function ->getAttributes (), $ namespace )
43- . 'function '
44- . ($ function ->getReturnReference () ? '& ' : '' )
45- . $ function ->getName ()
46- . $ this ->printParameters ($ function , $ namespace )
47- . $ this ->printReturnType ($ function , $ namespace )
48+ . $ line
49+ . $ this ->printParameters ($ function , $ namespace , strlen ($ line ) + strlen ($ returnType ) + 2 ) // 2 = parentheses
50+ . $ returnType
4851 . "\n{ \n" . $ this ->indent (ltrim (rtrim ($ function ->getBody ()) . "\n" )) . "} \n" ;
4952 }
5053
@@ -89,17 +92,20 @@ public function printArrowFunction(Closure $closure): string
8992 public function printMethod (Method $ method , PhpNamespace $ namespace = null ): string
9093 {
9194 $ method ->validate ();
92- return Helpers::formatDocComment ($ method ->getComment () . "\n" )
93- . self ::printAttributes ($ method ->getAttributes (), $ namespace )
94- . ($ method ->isAbstract () ? 'abstract ' : '' )
95+ $ line = ($ method ->isAbstract () ? 'abstract ' : '' )
9596 . ($ method ->isFinal () ? 'final ' : '' )
9697 . ($ method ->getVisibility () ? $ method ->getVisibility () . ' ' : '' )
9798 . ($ method ->isStatic () ? 'static ' : '' )
9899 . 'function '
99100 . ($ method ->getReturnReference () ? '& ' : '' )
100- . $ method ->getName ()
101- . ($ params = $ this ->printParameters ($ method , $ namespace ))
102- . $ this ->printReturnType ($ method , $ namespace )
101+ . $ method ->getName ();
102+ $ returnType = $ this ->printReturnType ($ method , $ namespace );
103+
104+ return Helpers::formatDocComment ($ method ->getComment () . "\n" )
105+ . self ::printAttributes ($ method ->getAttributes (), $ namespace )
106+ . $ line
107+ . ($ params = $ this ->printParameters ($ method , $ namespace , strlen ($ line ) + strlen ($ returnType ) + strlen ($ this ->indentation ) + 2 )) // 2 = parentheses
108+ . $ returnType
103109 . ($ method ->isAbstract () || $ method ->getBody () === null
104110 ? "; \n"
105111 : (strpos ($ params , "\n" ) === false ? "\n" : ' ' )
@@ -254,7 +260,7 @@ protected function printUses(PhpNamespace $namespace): string
254260 /**
255261 * @param Closure|GlobalFunction|Method $function
256262 */
257- public function printParameters ($ function , PhpNamespace $ namespace = null ): string
263+ public function printParameters ($ function , PhpNamespace $ namespace = null , int $ column = 0 ): string
258264 {
259265 $ params = [];
260266 $ list = $ function ->getParameters ();
@@ -279,7 +285,7 @@ public function printParameters($function, PhpNamespace $namespace = null): stri
279285
280286 $ line = implode (', ' , $ params );
281287
282- return count ($ params ) > 1 && ($ special || strlen ($ line ) > (new Dumper )->wrapLength )
288+ return count ($ params ) > 1 && ($ special || strlen ($ line ) + $ column > (new Dumper )->wrapLength )
283289 ? "( \n" . $ this ->indent (implode (", \n" , $ params )) . ($ special ? ', ' : '' ) . "\n) "
284290 : "( $ line) " ;
285291 }
0 commit comments