@@ -38,13 +38,16 @@ class Printer
38
38
39
39
public function printFunction (GlobalFunction $ function , PhpNamespace $ namespace = null ): string
40
40
{
41
+ $ line = 'function '
42
+ . ($ function ->getReturnReference () ? '& ' : '' )
43
+ . $ function ->getName ();
44
+ $ returnType = $ this ->printReturnType ($ function , $ namespace );
45
+
41
46
return Helpers::formatDocComment ($ function ->getComment () . "\n" )
42
47
. 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
48
51
. "\n{ \n" . $ this ->indent (ltrim (rtrim ($ function ->getBody ()) . "\n" )) . "} \n" ;
49
52
}
50
53
@@ -89,17 +92,20 @@ public function printArrowFunction(Closure $closure): string
89
92
public function printMethod (Method $ method , PhpNamespace $ namespace = null ): string
90
93
{
91
94
$ method ->validate ();
92
- return Helpers::formatDocComment ($ method ->getComment () . "\n" )
93
- . self ::printAttributes ($ method ->getAttributes (), $ namespace )
94
- . ($ method ->isAbstract () ? 'abstract ' : '' )
95
+ $ line = ($ method ->isAbstract () ? 'abstract ' : '' )
95
96
. ($ method ->isFinal () ? 'final ' : '' )
96
97
. ($ method ->getVisibility () ? $ method ->getVisibility () . ' ' : '' )
97
98
. ($ method ->isStatic () ? 'static ' : '' )
98
99
. 'function '
99
100
. ($ 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
103
109
. ($ method ->isAbstract () || $ method ->getBody () === null
104
110
? "; \n"
105
111
: (strpos ($ params , "\n" ) === false ? "\n" : ' ' )
@@ -254,7 +260,7 @@ protected function printUses(PhpNamespace $namespace): string
254
260
/**
255
261
* @param Closure|GlobalFunction|Method $function
256
262
*/
257
- public function printParameters ($ function , PhpNamespace $ namespace = null ): string
263
+ public function printParameters ($ function , PhpNamespace $ namespace = null , int $ column = 0 ): string
258
264
{
259
265
$ params = [];
260
266
$ list = $ function ->getParameters ();
@@ -279,7 +285,7 @@ public function printParameters($function, PhpNamespace $namespace = null): stri
279
285
280
286
$ line = implode (', ' , $ params );
281
287
282
- return count ($ params ) > 1 && ($ special || strlen ($ line ) > (new Dumper )->wrapLength )
288
+ return count ($ params ) > 1 && ($ special || strlen ($ line ) + $ column > (new Dumper )->wrapLength )
283
289
? "( \n" . $ this ->indent (implode (", \n" , $ params )) . ($ special ? ', ' : '' ) . "\n) "
284
290
: "( $ line) " ;
285
291
}
0 commit comments