1010use Box \Spout \Writer \Exception \WriterNotOpenedException ;
1111use Box \Spout \Writer \WriterInterface ;
1212use 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 ;
1713use Kiboko \Contract \Pipeline \LoaderInterface ;
1814use Psr \Log \LoggerInterface ;
1915use 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