@@ -35,7 +35,7 @@ public function printFunction(GlobalFunction $function, PhpNamespace $namespace
35
35
. $ function ->getName ()
36
36
. $ this ->printParameters ($ function , $ namespace )
37
37
. $ this ->printReturnType ($ function , $ namespace )
38
- . "\n{ \n" . $ this ->indent (ltrim (rtrim ($ function ->getBody ()) . "\n" )) . ' } ' ;
38
+ . "\n{ \n" . $ this ->indent (ltrim (rtrim ($ function ->getBody ()) . "\n" )) . " } \n" ;
39
39
}
40
40
41
41
@@ -71,11 +71,11 @@ public function printMethod(Method $method, PhpNamespace $namespace = null): str
71
71
. ($ params = $ this ->printParameters ($ method , $ namespace ))
72
72
. $ this ->printReturnType ($ method , $ namespace )
73
73
. ($ method ->isAbstract () || $ method ->getBody () === null
74
- ? ' ; '
74
+ ? " ; \n"
75
75
: (strpos ($ params , "\n" ) === false ? "\n" : ' ' )
76
76
. "{ \n"
77
77
. $ this ->indent (ltrim (rtrim ($ method ->getBody ()) . "\n" ))
78
- . ' } ' );
78
+ . " } \n" );
79
79
}
80
80
81
81
@@ -86,30 +86,36 @@ public function printClass(ClassType $class, PhpNamespace $namespace = null): st
86
86
$ traits = [];
87
87
foreach ($ class ->getTraitResolutions () as $ trait => $ resolutions ) {
88
88
$ traits [] = 'use ' . $ resolver ($ trait )
89
- . ($ resolutions ? " { \n" . $ this ->indentation . implode ("; \n" . $ this ->indentation , $ resolutions ) . "; \n} " : ' ; ' );
89
+ . ($ resolutions ? " { \n" . $ this ->indentation . implode ("; \n" . $ this ->indentation , $ resolutions ) . "; \n} \n " : " ; \n" );
90
90
}
91
91
92
92
$ consts = [];
93
93
foreach ($ class ->getConstants () as $ const ) {
94
94
$ consts [] = Helpers::formatDocComment ((string ) $ const ->getComment ())
95
95
. ($ const ->getVisibility () ? $ const ->getVisibility () . ' ' : '' )
96
- . 'const ' . $ const ->getName () . ' = ' . Helpers::dump ($ const ->getValue ()) . ' ; ' ;
96
+ . 'const ' . $ const ->getName () . ' = ' . Helpers::dump ($ const ->getValue ()) . " ; \n" ;
97
97
}
98
98
99
99
$ properties = [];
100
100
foreach ($ class ->getProperties () as $ property ) {
101
101
$ properties [] = Helpers::formatDocComment ((string ) $ property ->getComment ())
102
102
. ($ property ->getVisibility () ?: 'public ' ) . ($ property ->isStatic () ? ' static ' : '' ) . ' $ ' . $ property ->getName ()
103
103
. ($ property ->getValue () === null ? '' : ' = ' . Helpers::dump ($ property ->getValue ()))
104
- . ' ; ' ;
104
+ . " ; \n" ;
105
105
}
106
106
107
107
$ methods = [];
108
108
foreach ($ class ->getMethods () as $ method ) {
109
109
$ methods [] = $ this ->printMethod ($ method , $ namespace );
110
110
}
111
111
112
- $ methodSpace = str_repeat ("\n" , $ this ->linesBetweenMethods + 1 );
112
+ $ members = array_filter ([
113
+ implode ('' , $ traits ),
114
+ implode ('' , $ consts ),
115
+ implode ("\n" , $ properties ),
116
+ ($ methods && $ properties ? str_repeat ("\n" , $ this ->linesBetweenMethods - 1 ) : '' )
117
+ . implode (str_repeat ("\n" , $ this ->linesBetweenMethods ), $ methods ),
118
+ ]);
113
119
114
120
return Strings::normalize (
115
121
Helpers::formatDocComment ($ class ->getComment () . "\n" )
@@ -119,11 +125,7 @@ public function printClass(ClassType $class, PhpNamespace $namespace = null): st
119
125
. ($ class ->getExtends () ? 'extends ' . implode (', ' , array_map ($ resolver , (array ) $ class ->getExtends ())) . ' ' : '' )
120
126
. ($ class ->getImplements () ? 'implements ' . implode (', ' , array_map ($ resolver , $ class ->getImplements ())) . ' ' : '' )
121
127
. ($ class ->getName () ? "\n" : '' ) . "{ \n"
122
- . $ this ->indent (
123
- ($ traits ? implode ("\n" , $ traits ) . "\n\n" : '' )
124
- . ($ consts ? implode ("\n" , $ consts ) . "\n\n" : '' )
125
- . ($ properties ? implode ("\n\n" , $ properties ) . $ methodSpace : '' )
126
- . ($ methods ? implode ($ methodSpace , $ methods ) . "\n" : '' ))
128
+ . ($ members ? $ this ->indent (implode ("\n" , $ members )) : '' )
127
129
. '} '
128
130
) . ($ class ->getName () ? "\n" : '' );
129
131
}
@@ -155,9 +157,9 @@ public function printNamespace(PhpNamespace $namespace): string
155
157
. implode ("\n" , $ classes );
156
158
157
159
if ($ namespace ->getBracketedSyntax ()) {
158
- return 'namespace ' . ($ name ? " $ name " : '' ) . " { \n \n"
160
+ return 'namespace ' . ($ name ? " $ name " : '' ) . "\n { \n"
159
161
. $ this ->indent ($ body )
160
- . "\n } \n" ;
162
+ . "} \n" ;
161
163
162
164
} else {
163
165
return ($ name ? "namespace $ name; \n\n" : '' )
@@ -175,7 +177,8 @@ public function printFile(PhpFile $file): string
175
177
176
178
return Strings::normalize (
177
179
"<?php \n"
178
- . ($ file ->getComment () ? "\n" . Helpers::formatDocComment ($ file ->getComment () . "\n" ) . "\n" : '' )
180
+ . ($ file ->getComment () ? "\n" . Helpers::formatDocComment ($ file ->getComment () . "\n" ) : '' )
181
+ . "\n"
179
182
. ($ file ->getStrictTypes () ? "declare(strict_types=1); \n\n" : '' )
180
183
. implode ("\n\n" , $ namespaces )
181
184
) . "\n" ;
0 commit comments