@@ -44,13 +44,14 @@ public function printFunction(GlobalFunction $function, ?PhpNamespace $namespace
4444 . $ function ->getName ();
4545 $ returnType = $ this ->printReturnType ($ function );
4646 $ body = Helpers::simplifyTaggedNames ($ function ->getBody (), $ this ->namespace );
47+ $ body = ltrim (rtrim (Strings::normalize ($ body )) . "\n" );
4748
4849 return Helpers::formatDocComment ($ function ->getComment () . "\n" )
4950 . self ::printAttributes ($ function ->getAttributes ())
5051 . $ line
5152 . $ this ->printParameters ($ function , strlen ($ line ) + strlen ($ returnType ) + 2 ) // 2 = parentheses
5253 . $ returnType
53- . "\n{ \n" . $ this ->indent (ltrim ( rtrim ( $ body) . "\n" ) ) . "} \n" ;
54+ . "\n{ \n" . $ this ->indent ($ body ) . "} \n" ;
5455 }
5556
5657
@@ -66,14 +67,15 @@ public function printClosure(Closure $closure, ?PhpNamespace $namespace = null):
6667 ? "\n" . $ this ->indentation . implode (", \n" . $ this ->indentation , $ uses ) . ", \n"
6768 : $ tmp ;
6869 $ body = Helpers::simplifyTaggedNames ($ closure ->getBody (), $ this ->namespace );
70+ $ body = ltrim (rtrim (Strings::normalize ($ body )) . "\n" );
6971
7072 return self ::printAttributes ($ closure ->getAttributes (), inline: true )
7173 . 'function '
7274 . ($ closure ->getReturnReference () ? '& ' : '' )
7375 . $ this ->printParameters ($ closure )
7476 . ($ uses ? " use ( $ useStr) " : '' )
7577 . $ this ->printReturnType ($ closure )
76- . " { \n" . $ this ->indent (ltrim ( rtrim ( $ body) . "\n" ) ) . '} ' ;
78+ . " { \n" . $ this ->indent ($ body ) . '} ' ;
7779 }
7880
7981
@@ -93,7 +95,7 @@ public function printArrowFunction(Closure $closure, ?PhpNamespace $namespace =
9395 . ($ closure ->getReturnReference () ? '& ' : '' )
9496 . $ this ->printParameters ($ closure )
9597 . $ this ->printReturnType ($ closure )
96- . ' => ' . trim ($ body ) . '; ' ;
98+ . ' => ' . trim (Strings:: normalize ( $ body) ) . '; ' ;
9799 }
98100
99101
@@ -110,7 +112,8 @@ public function printMethod(Method $method, ?PhpNamespace $namespace = null, boo
110112 . $ method ->getName ();
111113 $ returnType = $ this ->printReturnType ($ method );
112114 $ params = $ this ->printParameters ($ method , strlen ($ line ) + strlen ($ returnType ) + strlen ($ this ->indentation ) + 2 );
113- $ body = Helpers::simplifyTaggedNames ((string ) $ method ->getBody (), $ this ->namespace );
115+ $ body = Helpers::simplifyTaggedNames ($ method ->getBody (), $ this ->namespace );
116+ $ body = ltrim (rtrim (Strings::normalize ($ body )) . "\n" );
114117
115118 return Helpers::formatDocComment ($ method ->getComment () . "\n" )
116119 . self ::printAttributes ($ method ->getAttributes ())
@@ -119,10 +122,7 @@ public function printMethod(Method $method, ?PhpNamespace $namespace = null, boo
119122 . $ returnType
120123 . ($ method ->isAbstract () || $ isInterface
121124 ? "; \n"
122- : (str_contains ($ params , "\n" ) ? ' ' : "\n" )
123- . "{ \n"
124- . $ this ->indent (ltrim (rtrim ($ body ) . "\n" ))
125- . "} \n" );
125+ : (str_contains ($ params , "\n" ) ? ' ' : "\n" ) . "{ \n" . $ this ->indent ($ body ) . "} \n" );
126126 }
127127
128128
0 commit comments