Skip to content

Commit d3bd8c4

Browse files
authored
Merge pull request #23 from php-etl/fix/file-used-in-extractor
Fixed code generated in the extractor to prevent an error if a file d…
2 parents 4636a13 + 2a0de88 commit d3bd8c4

File tree

3 files changed

+27
-15
lines changed

3 files changed

+27
-15
lines changed

src/Builder/Extractor.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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
),

src/Builder/Loader.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ final class Loader 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, private bool $withNonStandard = false)
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, private bool $withNonStandard = false) {}
1715

1816
public function withFilePath(Node\Expr $filePath): self
1917
{

src/Builder/MultipleFilesLoader.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ final class MultipleFilesLoader implements StepBuilderInterface
1111
{
1212
private ?Node\Expr $logger = null;
1313

14-
public function __construct(private Node\Expr $filePath, private Node\Expr $maxLines, private ?Node\Expr $delimiter = null, private ?Node\Expr $enclosure = null, private ?Node\Expr $escape = null, private ?Node\Expr $columns = null, private bool $safeMode = true, private bool $withNonStandard = false)
15-
{
16-
}
14+
public function __construct(private Node\Expr $filePath, private Node\Expr $maxLines, private ?Node\Expr $delimiter = null, private ?Node\Expr $enclosure = null, private ?Node\Expr $escape = null, private ?Node\Expr $columns = null, private bool $safeMode = true, private bool $withNonStandard = false) {}
1715

1816
public function withFilePath(Node\Expr $filePath): self
1917
{

0 commit comments

Comments
 (0)