@@ -11,9 +11,7 @@ final class Extractor implements StepBuilderInterface
1111{
1212 private ?Node \Expr $ logger = null ;
1313
14- public function __construct (private Node \Expr $ filePath , private ?Node \Expr $ delimiter = null , private ?Node \Expr $ enclosure = null , private ?Node \Expr $ escape = null , private ?Node \Expr $ columns = null , private bool $ safeMode = true )
15- {
16- }
14+ public function __construct (private Node \Expr $ filePath , private ?Node \Expr $ delimiter = null , private ?Node \Expr $ enclosure = null , private ?Node \Expr $ escape = null , private ?Node \Expr $ columns = null , private bool $ safeMode = true ) {}
1715
1816 public function withFilePath (Node \Expr $ filePath ): self
1917 {
@@ -85,12 +83,30 @@ public function getNode(): Node
8583 {
8684 $ arguments = [
8785 new Node \Arg (
88- value: new Node \Expr \New_ (
89- class: new Node \Name \FullyQualified ('SplFileObject ' ),
90- args: [
91- new Node \Arg ($ this ->filePath ),
92- new Node \Arg (new Node \Scalar \String_ ('r ' )),
93- ],
86+ value: new Node \Expr \Ternary (
87+ cond: new Node \Expr \FuncCall (
88+ name: new Node \Name ('file_exists ' ),
89+ args: [
90+ new Node \Arg (
91+ value: new Node \Expr \Assign (
92+ var: new Node \Expr \Variable ('file ' ),
93+ expr: $ this ->filePath ,
94+ )
95+ ),
96+ ],
97+ ),
98+ if: new Node \Expr \New_ (
99+ class: new Node \Name \FullyQualified ('SplFileObject ' ),
100+ args: [
101+ new Node \Arg (
102+ value: new Node \Expr \Variable ('file ' ),
103+ ),
104+ new Node \Arg (new Node \Scalar \String_ ('r ' )),
105+ ],
106+ ),
107+ else: new Node \Expr \New_ (
108+ class: new Node \Name \FullyQualified ('SplTempFileObject ' ),
109+ ),
94110 ),
95111 name: new Node \Identifier ('file ' ),
96112 ),
0 commit comments