Skip to content

Commit

Permalink
Fixed code generated in the extractor to prevent an error if a file d…
Browse files Browse the repository at this point in the history
…o not exists
  • Loading branch information
sebprt committed Sep 13, 2023
1 parent 4636a13 commit 402ae01
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/Builder/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,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

0 comments on commit 402ae01

Please sign in to comment.