Skip to content

Commit

Permalink
Merge pull request #23 from php-etl/fix/file-used-in-extractor
Browse files Browse the repository at this point in the history
Fixed code generated in the extractor to prevent an error if a file d…
  • Loading branch information
sebprt authored Sep 14, 2023
2 parents 4636a13 + 2a0de88 commit d3bd8c4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 15 deletions.
34 changes: 25 additions & 9 deletions src/Builder/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ final class Extractor implements StepBuilderInterface
{
private ?Node\Expr $logger = null;

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)
{
}
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) {}

public function withFilePath(Node\Expr $filePath): self
{
Expand Down Expand Up @@ -85,12 +83,30 @@ public function getNode(): Node
{
$arguments = [
new Node\Arg(
value: new Node\Expr\New_(
class: new Node\Name\FullyQualified('SplFileObject'),
args: [
new Node\Arg($this->filePath),
new Node\Arg(new Node\Scalar\String_('r')),
],
value: new Node\Expr\Ternary(
cond: new Node\Expr\FuncCall(
name: new Node\Name('file_exists'),
args: [
new Node\Arg(
value: new Node\Expr\Assign(
var: new Node\Expr\Variable('file'),
expr: $this->filePath,
)
),
],
),
if: new Node\Expr\New_(
class: new Node\Name\FullyQualified('SplFileObject'),
args: [
new Node\Arg(
value: new Node\Expr\Variable('file'),
),
new Node\Arg(new Node\Scalar\String_('r')),
],
),
else: new Node\Expr\New_(
class: new Node\Name\FullyQualified('SplTempFileObject'),
),
),
name: new Node\Identifier('file'),
),
Expand Down
4 changes: 1 addition & 3 deletions src/Builder/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ final class Loader implements StepBuilderInterface
{
private ?Node\Expr $logger = null;

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)
{
}
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) {}

public function withFilePath(Node\Expr $filePath): self
{
Expand Down
4 changes: 1 addition & 3 deletions src/Builder/MultipleFilesLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ final class MultipleFilesLoader implements StepBuilderInterface
{
private ?Node\Expr $logger = null;

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)
{
}
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) {}

public function withFilePath(Node\Expr $filePath): self
{
Expand Down

0 comments on commit d3bd8c4

Please sign in to comment.