@@ -27,6 +27,14 @@ public function startVisitingClass(PhpClass $class)
27
27
$ this ->writer ->write ('namespace ' .$ namespace .'; ' ."\n\n" );
28
28
}
29
29
30
+ if ($ files = $ class ->getRequiredFiles ()) {
31
+ foreach ($ files as $ file ) {
32
+ $ this ->writer ->writeln ('require_once ' .var_export ($ file , true ).'; ' );
33
+ }
34
+
35
+ $ this ->writer ->write ("\n" );
36
+ }
37
+
30
38
if ($ useStatements = $ class ->getUseStatements ()) {
31
39
foreach ($ useStatements as $ alias => $ namespace ) {
32
40
$ this ->writer ->write ('use ' .$ namespace );
@@ -35,7 +43,7 @@ public function startVisitingClass(PhpClass $class)
35
43
$ this ->writer ->write (' as ' .$ alias );
36
44
}
37
45
38
- $ this ->writer ->write ("\n" );
46
+ $ this ->writer ->write ("; \n" );
39
47
}
40
48
41
49
$ this ->writer ->write ("\n" );
@@ -113,7 +121,7 @@ public function startVisitingMethods()
113
121
public function visitMethod (PhpMethod $ method )
114
122
{
115
123
if ($ docblock = $ method ->getDocblock ()) {
116
- $ this ->writer ->write ($ docblock );
124
+ $ this ->writer ->writeln ($ docblock)-> rtrim ( );
117
125
}
118
126
119
127
if ($ method ->isAbstract ()) {
@@ -128,30 +136,7 @@ public function visitMethod(PhpMethod $method)
128
136
129
137
$ this ->writer ->write ('function ' .$ method ->getName ().'( ' );
130
138
131
- $ first = true ;
132
- foreach ($ method ->getParameters () as $ parameter ) {
133
- if (!$ first ) {
134
- $ this ->writer ->write (', ' );
135
- }
136
- $ first = false ;
137
-
138
- if ($ type = $ parameter ->getType ()) {
139
- $ this ->writer ->write (
140
- ('array ' === $ type ? 'array ' : ('\\' === $ type [0 ] ? $ type : '\\' . $ type ))
141
- .' '
142
- );
143
- }
144
-
145
- if ($ parameter ->isPassedByReference ()) {
146
- $ this ->writer ->write ('& ' );
147
- }
148
-
149
- $ this ->writer ->write ('$ ' .$ parameter ->getName ());
150
-
151
- if ($ parameter ->hasDefaultValue ()) {
152
- $ this ->writer ->write (' = ' .var_export ($ parameter ->getDefaultValue (), true ));
153
- }
154
- }
139
+ $ this ->writeParameters ($ method ->getParameters ());
155
140
156
141
if ($ method ->isAbstract ()) {
157
142
$ this ->writer ->write ("); \n\n" );
@@ -183,8 +168,54 @@ public function endVisitingClass(PhpClass $class)
183
168
;
184
169
}
185
170
171
+ public function visitFunction (PhpFunction $ function )
172
+ {
173
+ if ($ namespace = $ function ->getNamespace ()) {
174
+ $ this ->writer ->write ("namespace $ namespace; \n\n" );
175
+ }
176
+
177
+ $ this ->writer ->write ("function {$ function ->getName ()}( " );
178
+ $ this ->writeParameters ($ function ->getParameters ());
179
+ $ this ->writer
180
+ ->write (") \n{ \n" )
181
+ ->indent ()
182
+ ->writeln ($ function ->getBody ())
183
+ ->outdent ()
184
+ ->rtrim ()
185
+ ->write ('} ' )
186
+ ;
187
+ }
188
+
186
189
public function getContent ()
187
190
{
188
191
return $ this ->writer ->getContent ();
189
192
}
193
+
194
+ private function writeParameters (array $ parameters )
195
+ {
196
+ $ first = true ;
197
+ foreach ($ parameters as $ parameter ) {
198
+ if (!$ first ) {
199
+ $ this ->writer ->write (', ' );
200
+ }
201
+ $ first = false ;
202
+
203
+ if ($ type = $ parameter ->getType ()) {
204
+ $ this ->writer ->write (
205
+ ('array ' === $ type ? 'array ' : ('\\' === $ type [0 ] ? $ type : '\\' . $ type ))
206
+ .' '
207
+ );
208
+ }
209
+
210
+ if ($ parameter ->isPassedByReference ()) {
211
+ $ this ->writer ->write ('& ' );
212
+ }
213
+
214
+ $ this ->writer ->write ('$ ' .$ parameter ->getName ());
215
+
216
+ if ($ parameter ->hasDefaultValue ()) {
217
+ $ this ->writer ->write (' = ' .var_export ($ parameter ->getDefaultValue (), true ));
218
+ }
219
+ }
220
+ }
190
221
}
0 commit comments