@@ -46,8 +46,7 @@ public function printFunction(GlobalFunction $function, ?PhpNamespace $namespace
46
46
. $ function ->getName ();
47
47
$ returnType = $ this ->printReturnType ($ function );
48
48
$ params = $ this ->printParameters ($ function , strlen ($ line ) + strlen ($ returnType ) + 2 ); // 2 = parentheses
49
- $ body = Helpers::simplifyTaggedNames ($ function ->getBody (), $ this ->namespace );
50
- $ body = ltrim (rtrim (Strings::normalize ($ body )) . "\n" );
49
+ $ body = $ this ->printFunctionBody ($ function );
51
50
$ braceOnNextLine = $ this ->isBraceOnNextLine (str_contains ($ params , "\n" ), (bool ) $ returnType );
52
51
53
52
return $ this ->printDocComment ($ function )
@@ -71,8 +70,7 @@ public function printClosure(Closure $closure, ?PhpNamespace $namespace = null):
71
70
$ useStr = strlen ($ tmp = implode (', ' , $ uses )) > $ this ->wrapLength && count ($ uses ) > 1
72
71
? "\n" . $ this ->indentation . implode (", \n" . $ this ->indentation , $ uses ) . ", \n"
73
72
: $ tmp ;
74
- $ body = Helpers::simplifyTaggedNames ($ closure ->getBody (), $ this ->namespace );
75
- $ body = ltrim (rtrim (Strings::normalize ($ body )) . "\n" );
73
+ $ body = $ this ->printFunctionBody ($ closure );
76
74
77
75
return $ this ->printAttributes ($ closure ->getAttributes (), inline: true )
78
76
. 'function '
@@ -93,14 +91,14 @@ public function printArrowFunction(Closure $closure, ?PhpNamespace $namespace =
93
91
}
94
92
}
95
93
96
- $ body = Helpers:: simplifyTaggedNames ( $ closure -> getBody (), $ this -> namespace );
94
+ $ body = $ this -> printFunctionBody ( $ closure );
97
95
98
96
return $ this ->printAttributes ($ closure ->getAttributes ())
99
97
. 'fn '
100
98
. ($ closure ->getReturnReference () ? '& ' : '' )
101
99
. $ this ->printParameters ($ closure )
102
100
. $ this ->printReturnType ($ closure )
103
- . ' => ' . trim (Strings:: normalize ( $ body) ) . '; ' ;
101
+ . ' => ' . rtrim ( $ body, "\n" ) . '; ' ;
104
102
}
105
103
106
104
@@ -117,8 +115,7 @@ public function printMethod(Method $method, ?PhpNamespace $namespace = null, boo
117
115
. $ method ->getName ();
118
116
$ returnType = $ this ->printReturnType ($ method );
119
117
$ params = $ this ->printParameters ($ method , strlen ($ line ) + strlen ($ returnType ) + strlen ($ this ->indentation ) + 2 );
120
- $ body = Helpers::simplifyTaggedNames ($ method ->getBody (), $ this ->namespace );
121
- $ body = ltrim (rtrim (Strings::normalize ($ body )) . "\n" );
118
+ $ body = $ this ->printFunctionBody ($ method );
122
119
$ braceOnNextLine = $ this ->isBraceOnNextLine (str_contains ($ params , "\n" ), (bool ) $ returnType );
123
120
124
121
return $ this ->printDocComment ($ method )
@@ -132,6 +129,14 @@ public function printMethod(Method $method, ?PhpNamespace $namespace = null, boo
132
129
}
133
130
134
131
132
+ private function printFunctionBody (Closure |GlobalFunction |Method $ function ): string
133
+ {
134
+ $ code = Helpers::simplifyTaggedNames ($ function ->getBody (), $ this ->namespace );
135
+ $ code = Strings::normalize ($ code );
136
+ return ltrim (rtrim ($ code ) . "\n" );
137
+ }
138
+
139
+
135
140
public function printClass (
136
141
ClassType |InterfaceType |TraitType |EnumType $ class ,
137
142
?PhpNamespace $ namespace = null ,
0 commit comments