Skip to content

Commit b2af9c7

Browse files
committed
Improved the writer Management + ran php-cs-fixer
1 parent 9a70f6d commit b2af9c7

File tree

8 files changed

+19
-43
lines changed

8 files changed

+19
-43
lines changed

src/CSV/FingersCrossed/Extractor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public function __construct(
1818
private ReaderInterface $reader,
1919
private int $skipLines = 0,
2020
private LoggerInterface $logger = new NullLogger()
21-
) {}
21+
) {
22+
}
2223

2324
public function extract(): iterable
2425
{

src/CSV/FingersCrossed/Loader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
public function __construct(
2424
private WriterInterface $writer,
2525
private LoggerInterface $logger = new NullLogger()
26-
) {}
26+
) {
27+
}
2728

2829
public function load(): \Generator
2930
{

src/CSV/Safe/Extractor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public function __construct(
1818
private ReaderInterface $reader,
1919
private int $skipLines = 0,
2020
private LoggerInterface $logger = new NullLogger()
21-
) {}
21+
) {
22+
}
2223

2324
public function extract(): iterable
2425
{

src/CSV/Safe/Loader.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
public function __construct(
2424
private WriterInterface $writer,
2525
private LoggerInterface $logger = new NullLogger()
26-
) {}
26+
) {
27+
}
2728

2829
public function load(): \Generator
2930
{

src/Sheet/FingersCrossed/Extractor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public function __construct(
2121
private string $sheetName,
2222
private int $skipLines = 0,
2323
private LoggerInterface $logger = new NullLogger()
24-
) {}
24+
) {
25+
}
2526

2627
public function extract(): iterable
2728
{

src/Sheet/FingersCrossed/Loader.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@
1212
use Kiboko\Component\Bucket\AcceptanceResultBucket;
1313
use Kiboko\Component\Bucket\EmptyResultBucket;
1414
use Kiboko\Component\Bucket\RejectionResultBucket;
15-
use Kiboko\Contract\Bucket\ResultBucketInterface;
16-
use Kiboko\Contract\Pipeline\FlushableInterface;
1715
use Kiboko\Contract\Pipeline\LoaderInterface;
1816
use Psr\Log\LoggerInterface;
1917
use Psr\Log\NullLogger;
2018

21-
final readonly class Loader implements LoaderInterface, FlushableInterface
19+
final readonly class Loader implements LoaderInterface
2220
{
2321
public function __construct(
2422
private WriterInterface $writer,
@@ -65,11 +63,4 @@ public function load(): \Generator
6563
$line = yield new AcceptanceResultBucket($line);
6664
}
6765
}
68-
69-
public function flush(): ResultBucketInterface
70-
{
71-
$this->writer->close();
72-
73-
return new EmptyResultBucket();
74-
}
7566
}

src/Sheet/Safe/Extractor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ public function __construct(
2121
private string $sheetName,
2222
private int $skipLines = 0,
2323
private LoggerInterface $logger = new NullLogger()
24-
) {}
24+
) {
25+
}
2526

2627
public function extract(): iterable
2728
{

src/Sheet/Safe/Loader.php

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@
1010
use Box\Spout\Writer\Exception\WriterNotOpenedException;
1111
use Box\Spout\Writer\WriterInterface;
1212
use Kiboko\Component\Bucket\AcceptanceResultBucket;
13-
use Kiboko\Component\Bucket\EmptyResultBucket;
14-
use Kiboko\Component\Bucket\RejectionResultBucket;
15-
use Kiboko\Contract\Bucket\ResultBucketInterface;
16-
use Kiboko\Contract\Pipeline\FlushableInterface;
1713
use Kiboko\Contract\Pipeline\LoaderInterface;
1814
use Psr\Log\LoggerInterface;
1915
use Psr\Log\NullLogger;
2016

21-
final readonly class Loader implements LoaderInterface, FlushableInterface
17+
final readonly class Loader implements LoaderInterface
2218
{
2319
public function __construct(
2420
private WriterInterface $writer,
@@ -31,33 +27,23 @@ public function __construct(
3127

3228
public function load(): \Generator
3329
{
34-
$line = yield new EmptyResultBucket();
30+
$line = yield;
3531
$headers = array_keys($line);
3632
try {
3733
$this->writer->addRow(
3834
new Row(array_map(fn ($value) => new Cell($value), array_keys($line)), null)
3935
);
40-
} catch (IOException|WriterNotOpenedException $exception) {
36+
} catch (WriterNotOpenedException|IOException $exception) {
4137
$this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]);
42-
$line = yield new RejectionResultBucket(
43-
'Impossible to load data to the given CSV file.',
44-
$exception,
45-
$line
46-
);
38+
39+
return;
4740
}
4841

49-
/* @phpstan-ignore-next-line */
5042
while (true) {
5143
try {
5244
$this->writer->addRow($this->orderColumns($headers, $line));
53-
} catch (IOException|WriterNotOpenedException $exception) {
45+
} catch (WriterNotOpenedException|IOException $exception) {
5446
$this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]);
55-
$line = yield new RejectionResultBucket(
56-
'Impossible to load data to the given CSV file.',
57-
$exception,
58-
$line
59-
);
60-
continue;
6147
}
6248

6349
$line = yield new AcceptanceResultBucket($line);
@@ -73,11 +59,4 @@ private function orderColumns(array $headers, array $line): Row
7359

7460
return new Row($result, null);
7561
}
76-
77-
public function flush(): ResultBucketInterface
78-
{
79-
$this->writer->close();
80-
81-
return new EmptyResultBucket();
82-
}
8362
}

0 commit comments

Comments
 (0)