Skip to content

Commit d49ce99

Browse files
committed
Renamed method in MultipleFilesLoader + remove ? before non-optional arguments
1 parent afcc0a5 commit d49ce99

File tree

4 files changed

+80
-9
lines changed

4 files changed

+80
-9
lines changed

src/Builder/Extractor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ final class Extractor implements StepBuilderInterface
1212
private ?Node\Expr $logger;
1313

1414
public function __construct(
15-
private ?Node\Expr $filePath,
15+
private Node\Expr $filePath,
1616
private ?Node\Expr $delimiter = null,
1717
private ?Node\Expr $enclosure = null,
1818
private ?Node\Expr $escape = null,

src/Builder/Loader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ final class Loader implements StepBuilderInterface
1212
private ?Node\Expr $logger;
1313

1414
public function __construct(
15-
private ?Node\Expr $filePath,
15+
private Node\Expr $filePath,
1616
private ?Node\Expr $delimiter = null,
1717
private ?Node\Expr $enclosure = null,
1818
private ?Node\Expr $escape = null,

src/Builder/MultipleFilesLoader.php

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,18 @@
1010
final class MultipleFilesLoader implements StepBuilderInterface
1111
{
1212
private ?Node\Expr $logger;
13-
private bool $withoutEnclosure;
1413

1514
public function __construct(
16-
private ?Node\Expr $filePath,
17-
private ?Node\Expr $maxLines,
15+
private Node\Expr $filePath,
16+
private Node\Expr $maxLines,
1817
private ?Node\Expr $delimiter = null,
1918
private ?Node\Expr $enclosure = null,
2019
private ?Node\Expr $escape = null,
2120
private ?Node\Expr $columns = null,
2221
private bool $safeMode = true,
22+
private bool $withNonStandard = false,
2323
) {
2424
$this->logger = null;
25-
$this->withoutEnclosure = false;
2625
}
2726

2827
public function withFilePath(Node\Expr $filePath): self
@@ -91,9 +90,9 @@ public function withSafeMode(): self
9190
return $this;
9291
}
9392

94-
public function withoutEnclosure(): self
93+
public function withNonStandard(): self
9594
{
96-
$this->safeMode = true;
95+
$this->withNonStandard = true;
9796

9897
return $this;
9998
}
@@ -110,7 +109,77 @@ public function getNode(): Node
110109
$arguments = [
111110
new Node\Arg(
112111
value: new Node\Expr\New_(
113-
class: $this->withoutEnclosure ? new Node\Name\FullyQualified('GyroscopsGenerated\\SplFileObject') : new Node\Name\FullyQualified('SplFileObject'),
112+
class: $this->withNonStandard ? new Node\Stmt\Class_(
113+
name: 'SplFileObject',
114+
subNodes: [
115+
'extends' => new Node\Name\FullyQualified('SplFileObject'),
116+
'stmts' => [
117+
new Node\Stmt\Function_(
118+
name: 'fputcsv',
119+
subNodes: [
120+
'params' => [
121+
new Node\Param(
122+
var: new Node\Expr\Variable('fields'),
123+
type: 'array',
124+
),
125+
new Node\Param(
126+
var: new Node\Expr\Variable('separator'),
127+
default: new Node\Scalar\String_(','),
128+
type: 'string',
129+
),
130+
new Node\Param(
131+
var: new Node\Expr\Variable('enclosure'),
132+
default: new Node\Scalar\String_('"'),
133+
type: 'string',
134+
),
135+
new Node\Param(
136+
var: new Node\Expr\Variable('escape'),
137+
default: new Node\Scalar\String_('\\'),
138+
type: 'string',
139+
),
140+
new Node\Param(
141+
var: new Node\Expr\Variable('eol'),
142+
default: new Node\Expr\ConstFetch(new Node\Name('PHP_EOL')),
143+
type: 'string',
144+
),
145+
],
146+
'returnType' => new Node\UnionType(
147+
types: [
148+
new Node\Name('int'),
149+
new Node\Name('false'),
150+
],
151+
),
152+
'stmts' => [
153+
new Node\Stmt\Return_(
154+
expr: new Node\Expr\MethodCall(
155+
var: new Node\Expr\Variable('this'),
156+
name: 'fwrite',
157+
args: [
158+
new Node\Arg(
159+
value: new Node\Expr\BinaryOp\Concat(
160+
left: new Node\Expr\FuncCall(
161+
name: new Node\Name('implode'),
162+
args: [
163+
new Node\Arg(
164+
value: new Node\Expr\Variable('separator')
165+
),
166+
new Node\Arg(
167+
value: new Node\Expr\Variable('fields')
168+
),
169+
],
170+
),
171+
right: new Node\Expr\Variable('eol')
172+
),
173+
),
174+
],
175+
),
176+
),
177+
],
178+
],
179+
),
180+
],
181+
],
182+
) : new Node\Name\FullyQualified('SplFileObject'),
114183
args: [
115184
new Node\Arg(
116185
value: $this->filePath

src/Service.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Kiboko\Contract\Configurator;
88
use Symfony\Component\Config\Definition\Exception as Symfony;
99
use Symfony\Component\Config\Definition\Processor;
10+
use Symfony\Component\ExpressionLanguage\ExpressionFunctionProviderInterface;
1011
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
1112

1213
#[Configurator\Pipeline(
@@ -69,6 +70,7 @@ public function compile(array $config): Configurator\RepositoryInterface
6970
&& \count($config['expression_language'])
7071
) {
7172
foreach ($config['expression_language'] as $provider) {
73+
/** @var ExpressionFunctionProviderInterface $provider */
7274
$interpreter->registerProvider(new $provider());
7375
}
7476
}

0 commit comments

Comments
 (0)