@@ -11,9 +11,7 @@ final class Extractor implements StepBuilderInterface
11
11
{
12
12
private ?Node \Expr $ logger = null ;
13
13
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 ) {}
17
15
18
16
public function withFilePath (Node \Expr $ filePath ): self
19
17
{
@@ -85,12 +83,30 @@ public function getNode(): Node
85
83
{
86
84
$ arguments = [
87
85
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
+ ),
94
110
),
95
111
name: new Node \Identifier ('file ' ),
96
112
),
0 commit comments