Skip to content

Commit 402ae01

Browse files
committed
Fixed code generated in the extractor to prevent an error if a file do not exists
1 parent 4636a13 commit 402ae01

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/Builder/Extractor.php

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,30 @@ public function getNode(): Node
8585
{
8686
$arguments = [
8787
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-
],
88+
value: new Node\Expr\Ternary(
89+
cond: new Node\Expr\FuncCall(
90+
name: new Node\Name('file_exists'),
91+
args: [
92+
new Node\Arg(
93+
value: new Node\Expr\Assign(
94+
var: new Node\Expr\Variable('file'),
95+
expr: $this->filePath,
96+
)
97+
),
98+
],
99+
),
100+
if: new Node\Expr\New_(
101+
class: new Node\Name\FullyQualified('SplFileObject'),
102+
args: [
103+
new Node\Arg(
104+
value: new Node\Expr\Variable('file'),
105+
),
106+
new Node\Arg(new Node\Scalar\String_('r')),
107+
],
108+
),
109+
else: new Node\Expr\New_(
110+
class: new Node\Name\FullyQualified('SplTempFileObject'),
111+
),
94112
),
95113
name: new Node\Identifier('file'),
96114
),

0 commit comments

Comments
 (0)