Skip to content

Commit 21a0651

Browse files
authored
Merge pull request #5 from php-etl/fix/multiple-files
Fixed the number of lines per file : the max_number option includes t…
2 parents 4830575 + 4d87c31 commit 21a0651

File tree

4 files changed

+41
-30
lines changed

4 files changed

+41
-30
lines changed
Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Kiboko\Contract\Configurator\StepBuilderInterface;
66
use PhpParser\Node;
77

8-
final class MultipleFileLoader implements StepBuilderInterface
8+
final class MultipleFilesLoader implements StepBuilderInterface
99
{
1010
private ?Node\Expr $logger;
1111
private ?Node\Expr $rejection;
@@ -236,10 +236,8 @@ class: new Node\Name\FullyQualified('SplFileObject'),
236236
stmts: [
237237
new Node\Stmt\If_(
238238
cond: new Node\Expr\BinaryOp\GreaterOrEqual(
239-
new Node\Expr\PostInc(
240-
var: new Node\Expr\Variable('readLines')
241-
),
242-
$this->maxLines
239+
left: new Node\Expr\Variable('readLines'),
240+
right: $this->maxLines
243241
),
244242
subNodes: [
245243
'stmts' => [
@@ -277,20 +275,25 @@ class: new Node\Name\FullyQualified('SplFileObject'),
277275
args: [
278276
new Node\Arg(
279277
value: new Node\Expr\Variable('line')
280-
)
281-
]
282-
)
283-
)
284-
)
278+
),
279+
],
280+
),
281+
),
282+
),
283+
new Node\Stmt\Expression(
284+
expr: new Node\Expr\PostInc(
285+
var: new Node\Expr\Variable('readLines')
286+
),
287+
),
285288
]
286289
),
287290
new Node\Stmt\Expression(
288291
new Node\Expr\Yield_(
289292
value: new Node\Expr\Variable('bucket')
290-
)
291-
)
292-
]
293-
]
293+
),
294+
),
295+
],
296+
],
294297
),
295298
new Node\Stmt\ClassMethod(
296299
name: new Node\Identifier(name: 'coroutineFactory'),
@@ -314,33 +317,33 @@ class: new Node\Name\FullyQualified(
314317
: 'Kiboko\\Component\\Flow\\Csv\\FingersCrossed\\Loader',
315318
),
316319
args: $arguments
317-
)
318-
)
320+
),
321+
),
319322
),
320323
new Node\Stmt\Expression(
321324
new Node\Expr\Assign(
322325
var: new Node\Expr\Variable('coroutine'),
323326
expr: new Node\Expr\MethodCall(
324327
var: new Node\Expr\Variable('loader'),
325328
name: new Node\Identifier('load')
326-
)
327-
)
329+
),
330+
),
328331
),
329332
new Node\Stmt\Expression(
330333
new Node\Expr\MethodCall(
331334
var: new Node\Expr\Variable('coroutine'),
332335
name: new Node\Identifier('rewind')
333-
)
336+
),
334337
),
335338
new Node\Stmt\Return_(
336339
expr: new Node\Expr\Variable('coroutine'),
337-
)
338-
]
339-
]
340-
)
341-
]
342-
]
343-
)
340+
),
341+
],
342+
],
343+
),
344+
],
345+
],
346+
),
344347
);
345348
}
346349
}

src/Factory/Loader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function validate(array $config): bool
5353
public function compile(array $config): Repository\Loader
5454
{
5555
if (array_key_exists('max_lines', $config)) {
56-
$loader = new CSV\Builder\MultipleFileLoader(
56+
$loader = new CSV\Builder\MultipleFilesLoader(
5757
filePath: compileValueWhenExpression($this->interpreter, $config['file_path'], 'index'),
5858
maxLines: compileValueWhenExpression($this->interpreter, $config['max_lines']),
5959
delimiter: array_key_exists('delimiter', $config) ? compileValueWhenExpression($this->interpreter, $config['delimiter']) : null,

src/Factory/Repository/Loader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ final class Loader implements Configurator\StepRepositoryInterface
99
{
1010
use RepositoryTrait;
1111

12-
public function __construct(private CSV\Builder\Loader|CSV\Builder\MultipleFileLoader $builder)
12+
public function __construct(private CSV\Builder\Loader|CSV\Builder\MultipleFilesLoader $builder)
1313
{
1414
$this->files = [];
1515
$this->packages = [];
1616
}
1717

18-
public function getBuilder(): CSV\Builder\Loader|CSV\Builder\MultipleFileLoader
18+
public function getBuilder(): CSV\Builder\Loader|CSV\Builder\MultipleFilesLoader
1919
{
2020
return $this->builder;
2121
}

tests/functional/Builder/MultipleFilesLoaderTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function testWithoutOptions(): void
4545
4646
CSV);
4747

48-
$loader = new Builder\MultipleFileLoader(
48+
$loader = new Builder\MultipleFilesLoader(
4949
filePath: compileExpression(new \functional\Kiboko\Plugin\CSV\ExpressionLanguage\ExpressionLanguage(), new Expression('format("vfs://SKU_%06d.csv", index)'), 'index'),
5050
maxLines: new Node\Scalar\LNumber(3)
5151
);
@@ -76,6 +76,10 @@ public function testWithoutOptions(): void
7676
'firstname' => 'Billy',
7777
'lastname' => 'Hess',
7878
],
79+
[
80+
'firstname' => 'Henry',
81+
'lastname' => 'Sellers',
82+
],
7983
],
8084
[
8185
[
@@ -102,6 +106,10 @@ public function testWithoutOptions(): void
102106
'firstname' => 'Billy',
103107
'lastname' => 'Hess',
104108
],
109+
[
110+
'firstname' => 'Henry',
111+
'lastname' => 'Sellers',
112+
],
105113
],
106114
$loader,
107115
);

0 commit comments

Comments
 (0)