Skip to content

Commit 192f6b6

Browse files
committed
Fixed design problem : add rejection buckets
1 parent 55be771 commit 192f6b6

File tree

4 files changed

+46
-10
lines changed

4 files changed

+46
-10
lines changed

src/CSV/FingersCrossed/Loader.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Box\Spout\Writer\WriterInterface;
1212
use Kiboko\Component\Bucket\AcceptanceResultBucket;
1313
use Kiboko\Component\Bucket\EmptyResultBucket;
14+
use Kiboko\Component\Bucket\RejectionResultBucket;
1415
use Kiboko\Contract\Bucket\ResultBucketInterface;
1516
use Kiboko\Contract\Pipeline\FlushableInterface;
1617
use Kiboko\Contract\Pipeline\LoaderInterface;
@@ -26,24 +27,32 @@ public function __construct(
2627

2728
public function load(): \Generator
2829
{
29-
$line = yield new EmptyResultBucket();
30+
$line = yield;
3031
try {
3132
$this->writer->addRow(
3233
new Row(array_map(fn ($value) => new Cell($value), array_keys($line)), null)
3334
);
3435
} catch (IOException|WriterNotOpenedException $exception) {
3536
$this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]);
36-
37-
return;
37+
$line = yield new RejectionResultBucket(
38+
'Impossible to load data to the given CSV file.',
39+
$exception,
40+
$line
41+
);
3842
}
3943

40-
while ($line) {
44+
while (true) {
4145
try {
4246
$this->writer->addRow(
4347
new Row(array_map(fn ($value) => new Cell($value), $line), null)
4448
);
4549
} catch (IOException|WriterNotOpenedException $exception) {
4650
$this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]);
51+
$line = yield new RejectionResultBucket(
52+
'Impossible to load data to the given CSV file.',
53+
$exception,
54+
$line
55+
);
4756
}
4857

4958
$line = yield new AcceptanceResultBucket($line);

src/CSV/Safe/Loader.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Box\Spout\Writer\WriterInterface;
1212
use Kiboko\Component\Bucket\AcceptanceResultBucket;
1313
use Kiboko\Component\Bucket\EmptyResultBucket;
14+
use Kiboko\Component\Bucket\RejectionResultBucket;
1415
use Kiboko\Contract\Bucket\ResultBucketInterface;
1516
use Kiboko\Contract\Pipeline\FlushableInterface;
1617
use Kiboko\Contract\Pipeline\LoaderInterface;
@@ -34,15 +35,23 @@ public function load(): \Generator
3435
);
3536
} catch (IOException|WriterNotOpenedException $exception) {
3637
$this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]);
37-
38-
return;
38+
$line = yield new RejectionResultBucket(
39+
'Impossible to load data to the given CSV file.',
40+
$exception,
41+
$line
42+
);
3943
}
4044

4145
while ($line) {
4246
try {
4347
$this->writer->addRow($this->orderColumns($headers, $line));
4448
} catch (IOException|WriterNotOpenedException $exception) {
4549
$this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]);
50+
$line = yield new RejectionResultBucket(
51+
'Impossible to load data to the given CSV file.',
52+
$exception,
53+
$line
54+
);
4655
}
4756

4857
$line = yield new AcceptanceResultBucket($line);

src/Sheet/FingersCrossed/Loader.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Box\Spout\Writer\WriterInterface;
1212
use Kiboko\Component\Bucket\AcceptanceResultBucket;
1313
use Kiboko\Component\Bucket\EmptyResultBucket;
14+
use Kiboko\Component\Bucket\RejectionResultBucket;
1415
use Kiboko\Contract\Bucket\ResultBucketInterface;
1516
use Kiboko\Contract\Pipeline\FlushableInterface;
1617
use Kiboko\Contract\Pipeline\LoaderInterface;
@@ -38,8 +39,11 @@ public function load(): \Generator
3839
);
3940
} catch (IOException|WriterNotOpenedException $exception) {
4041
$this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]);
41-
42-
return;
42+
$line = yield new RejectionResultBucket(
43+
'Impossible to load data to the given CSV file.',
44+
$exception,
45+
$line
46+
);
4347
}
4448

4549
while ($line) {
@@ -49,6 +53,11 @@ public function load(): \Generator
4953
);
5054
} catch (IOException|WriterNotOpenedException $exception) {
5155
$this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]);
56+
$line = yield new RejectionResultBucket(
57+
'Impossible to load data to the given CSV file.',
58+
$exception,
59+
$line
60+
);
5261
}
5362

5463
$line = yield new AcceptanceResultBucket($line);

src/Sheet/Safe/Loader.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Box\Spout\Writer\WriterInterface;
1212
use Kiboko\Component\Bucket\AcceptanceResultBucket;
1313
use Kiboko\Component\Bucket\EmptyResultBucket;
14+
use Kiboko\Component\Bucket\RejectionResultBucket;
1415
use Kiboko\Contract\Bucket\ResultBucketInterface;
1516
use Kiboko\Contract\Pipeline\FlushableInterface;
1617
use Kiboko\Contract\Pipeline\LoaderInterface;
@@ -38,15 +39,23 @@ public function load(): \Generator
3839
);
3940
} catch (IOException|WriterNotOpenedException $exception) {
4041
$this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]);
41-
42-
return;
42+
$line = yield new RejectionResultBucket(
43+
'Impossible to load data to the given CSV file.',
44+
$exception,
45+
$line
46+
);
4347
}
4448

4549
while ($line) {
4650
try {
4751
$this->writer->addRow($this->orderColumns($headers, $line));
4852
} catch (IOException|WriterNotOpenedException $exception) {
4953
$this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]);
54+
$line = yield new RejectionResultBucket(
55+
'Impossible to load data to the given CSV file.',
56+
$exception,
57+
$line
58+
);
5059
}
5160

5261
$line = yield new AcceptanceResultBucket($line);

0 commit comments

Comments
 (0)