From e2b9c621397ce38e163ed88bcf3b664ee4ab0141 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Planchat?= Date: Tue, 14 Nov 2023 16:22:58 +0100 Subject: [PATCH] Fixing PHPStan level 8 issues --- .github/workflows/phpstan-5.yaml | 23 --------- .github/workflows/phpstan-6.yaml | 23 --------- .github/workflows/phpstan-7.yaml | 23 --------- .../{phpstan-8.yaml => phpstan-9.yaml} | 2 +- .github/workflows/quality.yaml | 2 +- .php-cs-fixer.dist.php | 1 + README.md | 7 +-- composer.lock | 24 ++++----- src/GeneratorWrapper.php | 8 +-- src/Pipeline.php | 49 +++++++------------ src/PipelineRunner.php | 10 ---- src/Transformer/BatchingTransformer.php | 4 +- src/Transformer/FilterTransformer.php | 4 +- src/UnexpectedYieldedValueType.php | 2 - 14 files changed, 43 insertions(+), 139 deletions(-) delete mode 100644 .github/workflows/phpstan-5.yaml delete mode 100644 .github/workflows/phpstan-6.yaml delete mode 100644 .github/workflows/phpstan-7.yaml rename .github/workflows/{phpstan-8.yaml => phpstan-9.yaml} (96%) diff --git a/.github/workflows/phpstan-5.yaml b/.github/workflows/phpstan-5.yaml deleted file mode 100644 index 906b4c9..0000000 --- a/.github/workflows/phpstan-5.yaml +++ /dev/null @@ -1,23 +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' - - name: PHPStan - uses: php-actions/phpstan@v3 - with: - path: src/ - level: 5 - php_version: '8.2' diff --git a/.github/workflows/phpstan-6.yaml b/.github/workflows/phpstan-6.yaml deleted file mode 100644 index a367107..0000000 --- a/.github/workflows/phpstan-6.yaml +++ /dev/null @@ -1,23 +0,0 @@ -name: PHPStan level 6 -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' - - name: PHPStan - uses: php-actions/phpstan@v3 - with: - path: src/ - level: 6 - php_version: '8.2' diff --git a/.github/workflows/phpstan-7.yaml b/.github/workflows/phpstan-7.yaml deleted file mode 100644 index cad733d..0000000 --- a/.github/workflows/phpstan-7.yaml +++ /dev/null @@ -1,23 +0,0 @@ -name: PHPStan level 7 -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' - - name: PHPStan - uses: php-actions/phpstan@v3 - with: - path: src/ - level: 7 - php_version: '8.2' diff --git a/.github/workflows/phpstan-8.yaml b/.github/workflows/phpstan-9.yaml similarity index 96% rename from .github/workflows/phpstan-8.yaml rename to .github/workflows/phpstan-9.yaml index 8d7aec6..f1a358f 100644 --- a/.github/workflows/phpstan-8.yaml +++ b/.github/workflows/phpstan-9.yaml @@ -19,5 +19,5 @@ jobs: uses: php-actions/phpstan@v3 with: path: src/ - level: 8 + level: 9 php_version: '8.2' diff --git a/.github/workflows/quality.yaml b/.github/workflows/quality.yaml index 81521af..48b1431 100644 --- a/.github/workflows/quality.yaml +++ b/.github/workflows/quality.yaml @@ -33,5 +33,5 @@ jobs: uses: php-actions/phpstan@v3 with: path: src/ - level: 4 + level: 8 php_version: '8.2' diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 2a172a0..886cf6c 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -34,6 +34,7 @@ 'error_suppression' => true, 'ereg_to_preg' => true, 'dir_constant' => true, + 'phpdoc_align' => ['align' => 'left'], ]) ->setFinder($finder) ->setCacheFile('.php-cs-fixer.cache') // forward compatibility with 3.x line diff --git a/README.md b/README.md index d28acef..5496992 100644 --- a/README.md +++ b/README.md @@ -5,13 +5,10 @@ This package brings an implementation for the pipeline component, aimed at provi with logging, line rejections and execution states. -[![Quality (PHPStan level 4)](https://github.com/php-etl/pipeline/actions/workflows/quality.yaml/badge.svg)](https://github.com/php-etl/pipeline/actions/workflows/quality.yaml) +[![Quality (PHPStan level 8)](https://github.com/php-etl/pipeline/actions/workflows/quality.yaml/badge.svg)](https://github.com/php-etl/pipeline/actions/workflows/quality.yaml) [![PHPUnit](https://github.com/php-etl/pipeline/actions/workflows/phpunit.yaml/badge.svg)](https://github.com/php-etl/pipeline/actions/workflows/phpunit.yaml) [![Mutations](https://github.com/php-etl/pipeline/actions/workflows/infection.yaml/badge.svg)](https://github.com/php-etl/pipeline/actions/workflows/infection.yaml) -[![PHPStan level 5](https://github.com/php-etl/pipeline/actions/workflows/phpstan-5.yaml/badge.svg)](https://github.com/php-etl/pipeline/actions/workflows/phpstan-5.yaml) -[![PHPStan level 5](https://github.com/php-etl/pipeline/actions/workflows/phpstan-6.yaml/badge.svg)](https://github.com/php-etl/pipeline/actions/workflows/phpstan-6.yaml) -[![PHPStan level 7](https://github.com/php-etl/pipeline/actions/workflows/phpstan-7.yaml/badge.svg)](https://github.com/php-etl/pipeline/actions/workflows/phpstan-7.yaml) -[![PHPStan level 8](https://github.com/php-etl/pipeline/actions/workflows/phpstan-8.yaml/badge.svg)](https://github.com/php-etl/pipeline/actions/workflows/phpstan-8.yaml) +[![PHPStan level 9](https://github.com/php-etl/pipeline/actions/workflows/phpstan-9.yaml/badge.svg)](https://github.com/php-etl/pipeline/actions/workflows/phpstan-9.yaml) ![PHP](https://img.shields.io/packagist/php-v/php-etl/pipeline) Documentation diff --git a/composer.lock b/composer.lock index d1d20e2..0a9ed0b 100644 --- a/composer.lock +++ b/composer.lock @@ -12,12 +12,12 @@ "source": { "type": "git", "url": "https://github.com/php-etl/bucket.git", - "reference": "3e25f9ca7a85c7c05a72c004407f13da501248c0" + "reference": "233beac60eac83944160a5af993c20536d1ea1b0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-etl/bucket/zipball/3e25f9ca7a85c7c05a72c004407f13da501248c0", - "reference": "3e25f9ca7a85c7c05a72c004407f13da501248c0", + "url": "https://api.github.com/repos/php-etl/bucket/zipball/233beac60eac83944160a5af993c20536d1ea1b0", + "reference": "233beac60eac83944160a5af993c20536d1ea1b0", "shasum": "" }, "require": { @@ -61,7 +61,7 @@ "issues": "https://github.com/php-etl/bucket/issues", "source": "https://github.com/php-etl/bucket/tree/main" }, - "time": "2023-11-14T11:38:59+00:00" + "time": "2023-11-14T14:39:36+00:00" }, { "name": "php-etl/bucket-contracts", @@ -69,12 +69,12 @@ "source": { "type": "git", "url": "https://github.com/php-etl/bucket-contracts.git", - "reference": "b9595871228a1c41e9da9c6d9e883a28123f4a10" + "reference": "64170754cb1f5e556c8e526177be51d905c3b15f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-etl/bucket-contracts/zipball/b9595871228a1c41e9da9c6d9e883a28123f4a10", - "reference": "b9595871228a1c41e9da9c6d9e883a28123f4a10", + "url": "https://api.github.com/repos/php-etl/bucket-contracts/zipball/64170754cb1f5e556c8e526177be51d905c3b15f", + "reference": "64170754cb1f5e556c8e526177be51d905c3b15f", "shasum": "" }, "require": { @@ -116,7 +116,7 @@ "issues": "https://github.com/php-etl/bucket-contracts/issues", "source": "https://github.com/php-etl/bucket-contracts/tree/main" }, - "time": "2023-11-14T08:49:46+00:00" + "time": "2023-11-14T14:39:36+00:00" }, { "name": "php-etl/pipeline-contracts", @@ -124,12 +124,12 @@ "source": { "type": "git", "url": "https://github.com/php-etl/pipeline-contracts.git", - "reference": "03375b74ce813cd6f91c274de60db8523a65f6f7" + "reference": "2e752f6a766be9bec01c4ed43629e9b8d64e3059" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-etl/pipeline-contracts/zipball/03375b74ce813cd6f91c274de60db8523a65f6f7", - "reference": "03375b74ce813cd6f91c274de60db8523a65f6f7", + "url": "https://api.github.com/repos/php-etl/pipeline-contracts/zipball/2e752f6a766be9bec01c4ed43629e9b8d64e3059", + "reference": "2e752f6a766be9bec01c4ed43629e9b8d64e3059", "shasum": "" }, "require": { @@ -173,7 +173,7 @@ "issues": "https://github.com/php-etl/pipeline-contracts/issues", "source": "https://github.com/php-etl/pipeline-contracts/tree/main" }, - "time": "2023-11-14T14:14:40+00:00" + "time": "2023-11-14T14:57:53+00:00" }, { "name": "php-etl/satellite-contracts", diff --git a/src/GeneratorWrapper.php b/src/GeneratorWrapper.php index 2edfe43..ca8216e 100644 --- a/src/GeneratorWrapper.php +++ b/src/GeneratorWrapper.php @@ -11,7 +11,7 @@ */ class GeneratorWrapper { - /** @param \Iterator, Type> ...$iterators */ + /** @param \Iterator ...$iterators */ public function rewind(\Iterator ...$iterators): void { foreach ($iterators as $iterator) { @@ -19,7 +19,7 @@ public function rewind(\Iterator ...$iterators): void } } - /** @param \Iterator, Type> ...$iterators */ + /** @param \Iterator ...$iterators */ public function next(\Iterator ...$iterators): void { foreach ($iterators as $iterator) { @@ -27,7 +27,7 @@ public function next(\Iterator ...$iterators): void } } - /** @param \Iterator, Type> ...$iterators */ + /** @param \Iterator ...$iterators */ public function valid(\Iterator ...$iterators): bool { foreach ($iterators as $iterator) { @@ -40,7 +40,7 @@ public function valid(\Iterator ...$iterators): bool } /** - * @param Type $value + * @param Type $value * @param \Generator, Type, void> ...$generators */ public function send($value, \Generator ...$generators): \Generator diff --git a/src/Pipeline.php b/src/Pipeline.php index 4359cf5..e477969 100644 --- a/src/Pipeline.php +++ b/src/Pipeline.php @@ -22,9 +22,9 @@ class Pipeline implements PipelineInterface, WalkableInterface, RunnableInterface { - /** @var \AppendIterator, non-empty-array|object, \Iterator, non-empty-array|object>> */ + /** @var \AppendIterator> */ private readonly \AppendIterator $source; - /** @var \Iterator, non-empty-array|object>|\NoRewindIterator */ + /** @var \Iterator|\NoRewindIterator */ private iterable $subject; public function __construct( @@ -45,7 +45,9 @@ public function __construct( */ public function feed(...$data): void { - $this->source->append(new \ArrayIterator($data)); + /** @var \ArrayIterator $iterator */ + $iterator = new \ArrayIterator($data); + $this->source->append($iterator); } private function passThroughCoroutine(): \Generator @@ -60,8 +62,8 @@ private function passThroughCoroutine(): \Generator /** * @template Type * - * @param ExtractorInterface $extractor - * @param StepRejectionInterface $rejection + * @param ExtractorInterface $extractor + * @param StepRejectionInterface $rejection */ public function extract( StepCodeInterface $stepCode, @@ -71,36 +73,20 @@ public function extract( ): ExtractingInterface { $extract = $extractor->extract(); if (\is_array($extract)) { - $this->source->append( - $this->runner->run( - new \ArrayIterator($extract), - $this->passThroughCoroutine(), - $rejection, - $state, - ) - ); + /** @var \ArrayIterator $iterator */ + $iterator = new \ArrayIterator($extract); } elseif ($extract instanceof \Iterator) { - $this->source->append( - $this->runner->run( - $extract, - $this->passThroughCoroutine(), - $rejection, - $state, - ) - ); + /** @var \Iterator $iterator */ + $iterator = $extract; } elseif ($extract instanceof \Traversable) { - $this->source->append( - $this->runner->run( - new \IteratorIterator($extract), - $this->passThroughCoroutine(), - $rejection, - $state, - ) - ); + /** @var \IteratorIterator> $iterator */ + $iterator = new \IteratorIterator($extract); } else { throw new \RuntimeException('Invalid data source, expecting array or Traversable.'); } + $this->source->append($this->runner->run($iterator, $this->passThroughCoroutine(), $rejection, $state)); + return $this; } @@ -109,7 +95,7 @@ public function extract( * @template OutputType * * @param TransformerInterface $transformer - * @param StepRejectionInterface $rejection + * @param StepRejectionInterface $rejection */ public function transform( StepCodeInterface $stepCode, @@ -118,6 +104,7 @@ public function transform( StepStateInterface $state, ): TransformingInterface { if ($transformer instanceof FlushableInterface) { + /** @var \AppendIterator> $iterator */ $iterator = new \AppendIterator(); $iterator->append( @@ -158,7 +145,7 @@ public function transform( * @template OutputType * * @param LoaderInterface $loader - * @param StepRejectionInterface $rejection + * @param StepRejectionInterface $rejection */ public function load( StepCodeInterface $stepCode, diff --git a/src/PipelineRunner.php b/src/PipelineRunner.php index 3787f78..5795a81 100644 --- a/src/PipelineRunner.php +++ b/src/PipelineRunner.php @@ -21,16 +21,6 @@ public function __construct( private readonly LogLevel|string $rejectionLevel = LogLevel::WARNING ) {} - /** - * @template InputType - * @template OutputType - * - * @param \Iterator, InputType|null> $source - * @param \Generator|AcceptanceResultBucketInterface|RejectionResultBucketInterface|null, InputType, void> $coroutine - * @param StepRejectionInterface $rejection - * - * @return \Iterator, ResultBucketInterface> - */ public function run( \Iterator $source, \Generator $coroutine, diff --git a/src/Transformer/BatchingTransformer.php b/src/Transformer/BatchingTransformer.php index eeb010b..e8eaabd 100644 --- a/src/Transformer/BatchingTransformer.php +++ b/src/Transformer/BatchingTransformer.php @@ -66,9 +66,7 @@ public function transform(): \Generator public function flush(): ResultBucketInterface { if (\count($this->batch) <= 0) { - /** @var EmptyResultBucket $bucket */ - $bucket = new EmptyResultBucket(); - return $bucket; + return new EmptyResultBucket(); } /* @phpstan-ignore-next-line */ diff --git a/src/Transformer/FilterTransformer.php b/src/Transformer/FilterTransformer.php index 899c6d3..1722882 100644 --- a/src/Transformer/FilterTransformer.php +++ b/src/Transformer/FilterTransformer.php @@ -45,7 +45,9 @@ public function transform(): \Generator continue; } - $line = yield new AcceptanceResultBucket($line); + /** @var AcceptanceResultBucket $bucket */ + $bucket = new AcceptanceResultBucket($line); + $line = yield $bucket; } } } diff --git a/src/UnexpectedYieldedValueType.php b/src/UnexpectedYieldedValueType.php index 286b829..289866f 100644 --- a/src/UnexpectedYieldedValueType.php +++ b/src/UnexpectedYieldedValueType.php @@ -4,8 +4,6 @@ namespace Kiboko\Component\Pipeline; -use Kiboko\Contract\Bucket\ResultBucketInterface; - /** * @template InputType * @template OutputType