@@ -12,13 +12,14 @@ final class MultipleFilesLoader implements StepBuilderInterface
1212 private ?Node \Expr $ logger ;
1313
1414 public function __construct (
15- private ? Node \Expr $ filePath ,
16- private ? Node \Expr $ maxLines ,
15+ private Node \Expr $ filePath ,
16+ private Node \Expr $ maxLines ,
1717 private ?Node \Expr $ delimiter = null ,
1818 private ?Node \Expr $ enclosure = null ,
1919 private ?Node \Expr $ escape = null ,
2020 private ?Node \Expr $ columns = null ,
2121 private bool $ safeMode = true ,
22+ private bool $ withNonStandard = false ,
2223 ) {
2324 $ this ->logger = null ;
2425 }
@@ -89,6 +90,13 @@ public function withSafeMode(): self
8990 return $ this ;
9091 }
9192
93+ public function withNonStandard (): self
94+ {
95+ $ this ->withNonStandard = true ;
96+
97+ return $ this ;
98+ }
99+
92100 public function withFingersCrossedMode (): self
93101 {
94102 $ this ->safeMode = false ;
@@ -101,7 +109,78 @@ public function getNode(): Node
101109 $ arguments = [
102110 new Node \Arg (
103111 value: new Node \Expr \New_ (
104- class: new Node \Name \FullyQualified ('SplFileObject ' ),
112+ class: $ this ->withNonStandard ? new Node \Stmt \Class_ (
113+ name: 'SplFileObject ' ,
114+ subNodes: [
115+ 'extends ' => new Node \Name \FullyQualified ('SplFileObject ' ),
116+ 'stmts ' => [
117+ new Node \Stmt \ClassMethod (
118+ name: 'fputcsv ' ,
119+ subNodes: [
120+ 'type ' => Node \Stmt \Class_::MODIFIER_PUBLIC ,
121+ 'params ' => [
122+ new Node \Param (
123+ var: new Node \Expr \Variable ('fields ' ),
124+ type: 'array ' ,
125+ ),
126+ new Node \Param (
127+ var: new Node \Expr \Variable ('separator ' ),
128+ default: new Node \Scalar \String_ (', ' ),
129+ type: 'string ' ,
130+ ),
131+ new Node \Param (
132+ var: new Node \Expr \Variable ('enclosure ' ),
133+ default: new Node \Scalar \String_ ('" ' ),
134+ type: 'string ' ,
135+ ),
136+ new Node \Param (
137+ var: new Node \Expr \Variable ('escape ' ),
138+ default: new Node \Scalar \String_ ('\\' ),
139+ type: 'string ' ,
140+ ),
141+ new Node \Param (
142+ var: new Node \Expr \Variable ('eol ' ),
143+ default: new Node \Expr \ConstFetch (new Node \Name ('PHP_EOL ' )),
144+ type: 'string ' ,
145+ ),
146+ ],
147+ 'returnType ' => new Node \UnionType (
148+ types: [
149+ new Node \Name ('int ' ),
150+ new Node \Name ('false ' ),
151+ ],
152+ ),
153+ 'stmts ' => [
154+ new Node \Stmt \Return_ (
155+ expr: new Node \Expr \MethodCall (
156+ var: new Node \Expr \Variable ('this ' ),
157+ name: 'fwrite ' ,
158+ args: [
159+ new Node \Arg (
160+ value: new Node \Expr \BinaryOp \Concat (
161+ left: new Node \Expr \FuncCall (
162+ name: new Node \Name ('implode ' ),
163+ args: [
164+ new Node \Arg (
165+ value: new Node \Expr \Variable ('separator ' )
166+ ),
167+ new Node \Arg (
168+ value: new Node \Expr \Variable ('fields ' )
169+ ),
170+ ],
171+ ),
172+ right: new Node \Expr \Variable ('eol ' )
173+ ),
174+ ),
175+ ],
176+ ),
177+ ),
178+ ],
179+ ],
180+ ),
181+ ],
182+ ],
183+ ) : new Node \Name \FullyQualified ('SplFileObject ' ),
105184 args: [
106185 new Node \Arg (
107186 value: $ this ->filePath
@@ -174,7 +253,7 @@ class: new Node\Name\FullyQualified('SplFileObject'),
174253 var: new Node \Expr \Variable ('coroutine ' ),
175254 expr: new Node \Expr \MethodCall (
176255 var: new Node \Expr \Variable ('this ' ),
177- name: new Node \ Name ( 'coroutineFactory ' ) ,
256+ name: 'coroutineFactory ' ,
178257 args: [
179258 new Node \Arg (
180259 value: new Node \Expr \Assign (
0 commit comments