@@ -44,13 +44,14 @@ public function printFunction(GlobalFunction $function, ?PhpNamespace $namespace
44
44
. $ function ->getName ();
45
45
$ returnType = $ this ->printReturnType ($ function );
46
46
$ body = Helpers::simplifyTaggedNames ($ function ->getBody (), $ this ->namespace );
47
+ $ body = ltrim (rtrim (Strings::normalize ($ body )) . "\n" );
47
48
48
49
return Helpers::formatDocComment ($ function ->getComment () . "\n" )
49
50
. self ::printAttributes ($ function ->getAttributes ())
50
51
. $ line
51
52
. $ this ->printParameters ($ function , strlen ($ line ) + strlen ($ returnType ) + 2 ) // 2 = parentheses
52
53
. $ returnType
53
- . "\n{ \n" . $ this ->indent (ltrim ( rtrim ( $ body) . "\n" ) ) . "} \n" ;
54
+ . "\n{ \n" . $ this ->indent ($ body ) . "} \n" ;
54
55
}
55
56
56
57
@@ -66,14 +67,15 @@ public function printClosure(Closure $closure, ?PhpNamespace $namespace = null):
66
67
? "\n" . $ this ->indentation . implode (", \n" . $ this ->indentation , $ uses ) . ", \n"
67
68
: $ tmp ;
68
69
$ body = Helpers::simplifyTaggedNames ($ closure ->getBody (), $ this ->namespace );
70
+ $ body = ltrim (rtrim (Strings::normalize ($ body )) . "\n" );
69
71
70
72
return self ::printAttributes ($ closure ->getAttributes (), inline: true )
71
73
. 'function '
72
74
. ($ closure ->getReturnReference () ? '& ' : '' )
73
75
. $ this ->printParameters ($ closure )
74
76
. ($ uses ? " use ( $ useStr) " : '' )
75
77
. $ this ->printReturnType ($ closure )
76
- . " { \n" . $ this ->indent (ltrim ( rtrim ( $ body) . "\n" ) ) . '} ' ;
78
+ . " { \n" . $ this ->indent ($ body ) . '} ' ;
77
79
}
78
80
79
81
@@ -93,7 +95,7 @@ public function printArrowFunction(Closure $closure, ?PhpNamespace $namespace =
93
95
. ($ closure ->getReturnReference () ? '& ' : '' )
94
96
. $ this ->printParameters ($ closure )
95
97
. $ this ->printReturnType ($ closure )
96
- . ' => ' . trim ($ body ) . '; ' ;
98
+ . ' => ' . trim (Strings:: normalize ( $ body) ) . '; ' ;
97
99
}
98
100
99
101
@@ -110,7 +112,8 @@ public function printMethod(Method $method, ?PhpNamespace $namespace = null, boo
110
112
. $ method ->getName ();
111
113
$ returnType = $ this ->printReturnType ($ method );
112
114
$ 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" );
114
117
115
118
return Helpers::formatDocComment ($ method ->getComment () . "\n" )
116
119
. self ::printAttributes ($ method ->getAttributes ())
@@ -119,10 +122,7 @@ public function printMethod(Method $method, ?PhpNamespace $namespace = null, boo
119
122
. $ returnType
120
123
. ($ method ->isAbstract () || $ isInterface
121
124
? "; \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" );
126
126
}
127
127
128
128
0 commit comments