@@ -27,6 +27,14 @@ public function startVisitingClass(PhpClass $class)
2727 $ this ->writer ->write ('namespace ' .$ namespace .'; ' ."\n\n" );
2828 }
2929
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+
3038 if ($ useStatements = $ class ->getUseStatements ()) {
3139 foreach ($ useStatements as $ alias => $ namespace ) {
3240 $ this ->writer ->write ('use ' .$ namespace );
@@ -35,7 +43,7 @@ public function startVisitingClass(PhpClass $class)
3543 $ this ->writer ->write (' as ' .$ alias );
3644 }
3745
38- $ this ->writer ->write ("\n" );
46+ $ this ->writer ->write ("; \n" );
3947 }
4048
4149 $ this ->writer ->write ("\n" );
@@ -113,7 +121,7 @@ public function startVisitingMethods()
113121 public function visitMethod (PhpMethod $ method )
114122 {
115123 if ($ docblock = $ method ->getDocblock ()) {
116- $ this ->writer ->write ($ docblock );
124+ $ this ->writer ->writeln ($ docblock)-> rtrim ( );
117125 }
118126
119127 if ($ method ->isAbstract ()) {
@@ -128,30 +136,7 @@ public function visitMethod(PhpMethod $method)
128136
129137 $ this ->writer ->write ('function ' .$ method ->getName ().'( ' );
130138
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 ());
155140
156141 if ($ method ->isAbstract ()) {
157142 $ this ->writer ->write ("); \n\n" );
@@ -183,8 +168,54 @@ public function endVisitingClass(PhpClass $class)
183168 ;
184169 }
185170
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+
186189 public function getContent ()
187190 {
188191 return $ this ->writer ->getContent ();
189192 }
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+ }
190221}
0 commit comments