diff --git a/.github/workflows/infection.yaml b/.github/workflows/infection.yaml index c5adb1e..aacb82d 100644 --- a/.github/workflows/infection.yaml +++ b/.github/workflows/infection.yaml @@ -23,8 +23,8 @@ jobs: - name: Infection run: | - wget -q https://github.com/infection/infection/releases/download/0.26.18/infection.phar - wget -q https://github.com/infection/infection/releases/download/0.26.18/infection.phar.asc + wget -q https://github.com/infection/infection/releases/download/0.27.0/infection.phar + wget -q https://github.com/infection/infection/releases/download/0.27.0/infection.phar.asc chmod +x infection.phar ./infection.phar diff --git a/.github/workflows/phpstan-5.yaml b/.github/workflows/phpstan-5.yaml deleted file mode 100644 index 1d9e19f..0000000 --- a/.github/workflows/phpstan-5.yaml +++ /dev/null @@ -1,26 +0,0 @@ -name: PHPStan level 5 -on: push -jobs: - phpstan: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/cache@v3 - with: - path: '**/vendor' - key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: | - ${{ runner.os }}-composer- - - uses: php-actions/composer@v6 - with: - args: --prefer-dist - php_version: '8.2' - php_extensions: zip xdebug - - - name: PHPStan - uses: php-actions/phpstan@v3 - with: - path: src/ - level: 5 - php_version: '8.2' - php_extensions: zip xdebug diff --git a/.github/workflows/phpstan-6.yaml b/.github/workflows/phpstan-6.yaml index 57efd44..3362359 100644 --- a/.github/workflows/phpstan-6.yaml +++ b/.github/workflows/phpstan-6.yaml @@ -1,7 +1,7 @@ name: PHPStan level 6 on: push jobs: - phpstan: + phpstan-6: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/phpstan-7.yaml b/.github/workflows/phpstan-7.yaml index 1eacb3c..1a1a458 100644 --- a/.github/workflows/phpstan-7.yaml +++ b/.github/workflows/phpstan-7.yaml @@ -1,7 +1,7 @@ name: PHPStan level 7 on: push jobs: - phpstan: + phpstan-7: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/phpstan-8.yaml b/.github/workflows/phpstan-8.yaml index fa16164..417a3a7 100644 --- a/.github/workflows/phpstan-8.yaml +++ b/.github/workflows/phpstan-8.yaml @@ -1,7 +1,7 @@ name: PHPStan level 8 on: push jobs: - phpstan: + phpstan-8: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/quality.yaml b/.github/workflows/quality.yaml index c27d2d0..4d49f4d 100644 --- a/.github/workflows/quality.yaml +++ b/.github/workflows/quality.yaml @@ -1,4 +1,4 @@ -name: Quality (PHPStan level 4) +name: Quality (PHPStan level 5) on: push jobs: cs-fixer: @@ -34,6 +34,6 @@ jobs: uses: php-actions/phpstan@v3 with: path: src/ - level: 4 + level: 5 php_version: '8.2' php_extensions: zip xdebug diff --git a/README.md b/README.md index ef4bf2c..351982c 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ This package brings tools to read and write into spreadsheet files from a pipeli [![Quality](https://github.com/php-etl/spreadsheet-flow/actions/workflows/quality.yaml/badge.svg)](https://github.com/php-etl/spreadsheet-flow/actions/workflows/quality.yaml) -[![PHPStan level 5](https://github.com/php-etl/spreadsheet-flow/actions/workflows/phpstan-5.yaml/badge.svg)](https://github.com/php-etl/spreadsheet-flow/actions/workflows/phpstan-5.yaml) +[![PHPStan level 6](https://github.com/php-etl/spreadsheet-flow/actions/workflows/phpstan-6.yaml/badge.svg)](https://github.com/php-etl/spreadsheet-flow/actions/workflows/phpstan-6.yaml) [![PHPStan level 7](https://github.com/php-etl/spreadsheet-flow/actions/workflows/phpstan-7.yaml/badge.svg)](https://github.com/php-etl/spreadsheet-flow/actions/workflows/phpstan-7.yaml) [![PHPStan level 8](https://github.com/php-etl/spreadsheet-flow/actions/workflows/phpstan-8.yaml/badge.svg)](https://github.com/php-etl/spreadsheet-flow/actions/workflows/phpstan-8.yaml) ![PHP](https://img.shields.io/packagist/php-v/php-etl/spreadsheet-flow) diff --git a/phpunit.xml b/phpunit.xml index a0d7431..1f7dd58 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,30 +1,17 @@ - - - - tests/functional/ - - - - - src - - - - - + + + + tests/functional/ + + + + + + + + + src + + diff --git a/src/CSV/FingersCrossed/Extractor.php b/src/CSV/FingersCrossed/Extractor.php index 5a7a1dd..ecc1927 100644 --- a/src/CSV/FingersCrossed/Extractor.php +++ b/src/CSV/FingersCrossed/Extractor.php @@ -18,8 +18,7 @@ public function __construct( private ReaderInterface $reader, private int $skipLines = 0, private LoggerInterface $logger = new NullLogger() - ) { - } + ) {} public function extract(): iterable { diff --git a/src/CSV/FingersCrossed/Loader.php b/src/CSV/FingersCrossed/Loader.php index 7ec9185..7614357 100644 --- a/src/CSV/FingersCrossed/Loader.php +++ b/src/CSV/FingersCrossed/Loader.php @@ -11,6 +11,7 @@ use Box\Spout\Writer\WriterInterface; use Kiboko\Component\Bucket\AcceptanceResultBucket; use Kiboko\Component\Bucket\EmptyResultBucket; +use Kiboko\Component\Bucket\RejectionResultBucket; use Kiboko\Contract\Bucket\ResultBucketInterface; use Kiboko\Contract\Pipeline\FlushableInterface; use Kiboko\Contract\Pipeline\LoaderInterface; @@ -22,29 +23,38 @@ public function __construct( private WriterInterface $writer, private LoggerInterface $logger = new NullLogger() - ) { - } + ) {} public function load(): \Generator { - $line = yield; + $line = yield new EmptyResultBucket(); try { $this->writer->addRow( new Row(array_map(fn ($value) => new Cell($value), array_keys($line)), null) ); - } catch (WriterNotOpenedException|IOException $exception) { + } catch (IOException|WriterNotOpenedException $exception) { $this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]); - - return; + $line = yield new RejectionResultBucket( + 'Impossible to load data to the given CSV file.', + $exception, + $line + ); } + /* @phpstan-ignore-next-line */ while (true) { try { $this->writer->addRow( new Row(array_map(fn ($value) => new Cell($value), $line), null) ); - } catch (WriterNotOpenedException|IOException $exception) { + } catch (IOException|WriterNotOpenedException $exception) { $this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]); + $line = yield new RejectionResultBucket( + 'Impossible to load data to the given CSV file.', + $exception, + $line + ); + continue; } $line = yield new AcceptanceResultBucket($line); diff --git a/src/CSV/Safe/Extractor.php b/src/CSV/Safe/Extractor.php index 5aca5c0..0b0021b 100644 --- a/src/CSV/Safe/Extractor.php +++ b/src/CSV/Safe/Extractor.php @@ -18,8 +18,7 @@ public function __construct( private ReaderInterface $reader, private int $skipLines = 0, private LoggerInterface $logger = new NullLogger() - ) { - } + ) {} public function extract(): iterable { diff --git a/src/CSV/Safe/Loader.php b/src/CSV/Safe/Loader.php index cd88354..a27ed69 100644 --- a/src/CSV/Safe/Loader.php +++ b/src/CSV/Safe/Loader.php @@ -11,6 +11,7 @@ use Box\Spout\Writer\WriterInterface; use Kiboko\Component\Bucket\AcceptanceResultBucket; use Kiboko\Component\Bucket\EmptyResultBucket; +use Kiboko\Component\Bucket\RejectionResultBucket; use Kiboko\Contract\Bucket\ResultBucketInterface; use Kiboko\Contract\Pipeline\FlushableInterface; use Kiboko\Contract\Pipeline\LoaderInterface; @@ -22,28 +23,37 @@ public function __construct( private WriterInterface $writer, private LoggerInterface $logger = new NullLogger() - ) { - } + ) {} public function load(): \Generator { - $line = yield; + $line = yield new EmptyResultBucket(); $headers = array_keys($line); try { $this->writer->addRow( new Row(array_map(fn ($value) => new Cell($value), array_keys($line)), null) ); - } catch (WriterNotOpenedException|IOException $exception) { + } catch (IOException|WriterNotOpenedException $exception) { $this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]); - - return; + $line = yield new RejectionResultBucket( + 'Impossible to load data to the given CSV file.', + $exception, + $line + ); } + /* @phpstan-ignore-next-line */ while (true) { try { $this->writer->addRow($this->orderColumns($headers, $line)); - } catch (WriterNotOpenedException|IOException $exception) { + } catch (IOException|WriterNotOpenedException $exception) { $this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]); + $line = yield new RejectionResultBucket( + 'Impossible to load data to the given CSV file.', + $exception, + $line + ); + continue; } $line = yield new AcceptanceResultBucket($line); diff --git a/src/Sheet/FingersCrossed/Extractor.php b/src/Sheet/FingersCrossed/Extractor.php index 6ba9d0a..37d643d 100644 --- a/src/Sheet/FingersCrossed/Extractor.php +++ b/src/Sheet/FingersCrossed/Extractor.php @@ -21,8 +21,7 @@ public function __construct( private string $sheetName, private int $skipLines = 0, private LoggerInterface $logger = new NullLogger() - ) { - } + ) {} public function extract(): iterable { diff --git a/src/Sheet/FingersCrossed/Loader.php b/src/Sheet/FingersCrossed/Loader.php index dcdc77e..2321faa 100644 --- a/src/Sheet/FingersCrossed/Loader.php +++ b/src/Sheet/FingersCrossed/Loader.php @@ -11,6 +11,7 @@ use Box\Spout\Writer\WriterInterface; use Kiboko\Component\Bucket\AcceptanceResultBucket; use Kiboko\Component\Bucket\EmptyResultBucket; +use Kiboko\Component\Bucket\RejectionResultBucket; use Kiboko\Contract\Bucket\ResultBucketInterface; use Kiboko\Contract\Pipeline\FlushableInterface; use Kiboko\Contract\Pipeline\LoaderInterface; @@ -30,25 +31,35 @@ public function __construct( public function load(): \Generator { - $line = yield; + $line = yield new EmptyResultBucket(); try { $this->writer->addRow( new Row(array_map(fn ($value) => new Cell($value), array_keys($line)), null) ); - } catch (WriterNotOpenedException|IOException $exception) { + } catch (IOException|WriterNotOpenedException $exception) { $this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]); - - return; + $line = yield new RejectionResultBucket( + 'Impossible to load data to the given CSV file.', + $exception, + $line + ); } + /* @phpstan-ignore-next-line */ while (true) { try { $this->writer->addRow( new Row(array_map(fn ($value) => new Cell($value), $line), null) ); - } catch (WriterNotOpenedException|IOException $exception) { + } catch (IOException|WriterNotOpenedException $exception) { $this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]); + $line = yield new RejectionResultBucket( + 'Impossible to load data to the given CSV file.', + $exception, + $line + ); + continue; } $line = yield new AcceptanceResultBucket($line); diff --git a/src/Sheet/Safe/Extractor.php b/src/Sheet/Safe/Extractor.php index 62a9c1e..949312c 100644 --- a/src/Sheet/Safe/Extractor.php +++ b/src/Sheet/Safe/Extractor.php @@ -21,8 +21,7 @@ public function __construct( private string $sheetName, private int $skipLines = 0, private LoggerInterface $logger = new NullLogger() - ) { - } + ) {} public function extract(): iterable { diff --git a/src/Sheet/Safe/Loader.php b/src/Sheet/Safe/Loader.php index d00e6b5..bcea776 100644 --- a/src/Sheet/Safe/Loader.php +++ b/src/Sheet/Safe/Loader.php @@ -11,6 +11,7 @@ use Box\Spout\Writer\WriterInterface; use Kiboko\Component\Bucket\AcceptanceResultBucket; use Kiboko\Component\Bucket\EmptyResultBucket; +use Kiboko\Component\Bucket\RejectionResultBucket; use Kiboko\Contract\Bucket\ResultBucketInterface; use Kiboko\Contract\Pipeline\FlushableInterface; use Kiboko\Contract\Pipeline\LoaderInterface; @@ -30,23 +31,33 @@ public function __construct( public function load(): \Generator { - $line = yield; + $line = yield new EmptyResultBucket(); $headers = array_keys($line); try { $this->writer->addRow( new Row(array_map(fn ($value) => new Cell($value), array_keys($line)), null) ); - } catch (WriterNotOpenedException|IOException $exception) { + } catch (IOException|WriterNotOpenedException $exception) { $this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]); - - return; + $line = yield new RejectionResultBucket( + 'Impossible to load data to the given CSV file.', + $exception, + $line + ); } + /* @phpstan-ignore-next-line */ while (true) { try { $this->writer->addRow($this->orderColumns($headers, $line)); - } catch (WriterNotOpenedException|IOException $exception) { + } catch (IOException|WriterNotOpenedException $exception) { $this->logger->error('Impossible to load data to the given CSV file.', ['line' => $line, 'message' => $exception->getMessage(), 'previous' => $exception->getPrevious()]); + $line = yield new RejectionResultBucket( + 'Impossible to load data to the given CSV file.', + $exception, + $line + ); + continue; } $line = yield new AcceptanceResultBucket($line); diff --git a/tests/functional/PipelineRunner.php b/tests/functional/PipelineRunner.php index a6058a1..060dc00 100644 --- a/tests/functional/PipelineRunner.php +++ b/tests/functional/PipelineRunner.php @@ -7,20 +7,18 @@ use Kiboko\Contract\Bucket\AcceptanceResultBucketInterface; use Kiboko\Contract\Bucket\RejectionResultBucketInterface; use Kiboko\Contract\Pipeline\PipelineRunnerInterface; -use Kiboko\Contract\Pipeline\RejectionInterface; -use Kiboko\Contract\Pipeline\StateInterface; +use Kiboko\Contract\Pipeline\StepRejectionInterface; +use Kiboko\Contract\Pipeline\StepStateInterface; final class PipelineRunner implements PipelineRunnerInterface { public function run( \Iterator $source, \Generator $async, - RejectionInterface $rejection, - StateInterface $state, - ): \Iterator { - $state->initialize(); - $rejection->initialize(); - + StepRejectionInterface $rejection, + StepStateInterface $state, + ): \Iterator + { $source->rewind(); $async->rewind(); @@ -40,8 +38,5 @@ public function run( $source->next(); } - - $rejection->teardown(); - $state->teardown(); } }