Skip to content

Commit

Permalink
Fixing PHPStan level 8 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gplanchat committed Nov 14, 2023
1 parent bbc5991 commit e2b9c62
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 139 deletions.
23 changes: 0 additions & 23 deletions .github/workflows/phpstan-5.yaml

This file was deleted.

23 changes: 0 additions & 23 deletions .github/workflows/phpstan-6.yaml

This file was deleted.

23 changes: 0 additions & 23 deletions .github/workflows/phpstan-7.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ jobs:
uses: php-actions/phpstan@v3
with:
path: src/
level: 8
level: 9
php_version: '8.2'
2 changes: 1 addition & 1 deletion .github/workflows/quality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ jobs:
uses: php-actions/phpstan@v3
with:
path: src/
level: 4
level: 8
php_version: '8.2'
1 change: 1 addition & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/GeneratorWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
*/
class GeneratorWrapper
{
/** @param \Iterator<int<0, max>, Type> ...$iterators */
/** @param \Iterator<int, Type> ...$iterators */
public function rewind(\Iterator ...$iterators): void
{
foreach ($iterators as $iterator) {

Check warning on line 17 in src/GeneratorWrapper.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "Foreach_": --- Original +++ New @@ @@ /** @param \Iterator<int, Type> ...$iterators */ public function rewind(\Iterator ...$iterators) : void { - foreach ($iterators as $iterator) { + foreach (array() as $iterator) { $iterator->rewind(); } }
$iterator->rewind();

Check warning on line 18 in src/GeneratorWrapper.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ public function rewind(\Iterator ...$iterators) : void { foreach ($iterators as $iterator) { - $iterator->rewind(); + } } /** @param \Iterator<int, Type> ...$iterators */
}
}

/** @param \Iterator<int<0, max>, Type> ...$iterators */
/** @param \Iterator<int, Type> ...$iterators */
public function next(\Iterator ...$iterators): void
{
foreach ($iterators as $iterator) {
$iterator->next();
}
}

/** @param \Iterator<int<0, max>, Type> ...$iterators */
/** @param \Iterator<int, Type> ...$iterators */
public function valid(\Iterator ...$iterators): bool
{
foreach ($iterators as $iterator) {

Check warning on line 33 in src/GeneratorWrapper.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "Foreach_": --- Original +++ New @@ @@ /** @param \Iterator<int, Type> ...$iterators */ public function valid(\Iterator ...$iterators) : bool { - foreach ($iterators as $iterator) { + foreach (array() as $iterator) { if (!$iterator->valid()) { return false; }
Expand All @@ -40,7 +40,7 @@ public function valid(\Iterator ...$iterators): bool
}

/**
* @param Type $value
* @param Type $value
* @param \Generator<int, ResultBucketInterface<Type>, Type, void> ...$generators
*/
public function send($value, \Generator ...$generators): \Generator
Expand Down
49 changes: 18 additions & 31 deletions src/Pipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@

class Pipeline implements PipelineInterface, WalkableInterface, RunnableInterface
{
/** @var \AppendIterator<int<0, max>, non-empty-array<array-key, mixed>|object, \Iterator<int<0, max>, non-empty-array<array-key, mixed>|object>> */
/** @var \AppendIterator<int, mixed, \Iterator<int, mixed>> */
private readonly \AppendIterator $source;
/** @var \Iterator<int<0, max>, non-empty-array<array-key, mixed>|object>|\NoRewindIterator */
/** @var \Iterator<int, mixed>|\NoRewindIterator */
private iterable $subject;

public function __construct(
Expand All @@ -45,7 +45,9 @@ public function __construct(
*/
public function feed(...$data): void
{
$this->source->append(new \ArrayIterator($data));
/** @var \ArrayIterator<int, InputType> $iterator */
$iterator = new \ArrayIterator($data);
$this->source->append($iterator);
}

private function passThroughCoroutine(): \Generator
Expand All @@ -60,8 +62,8 @@ private function passThroughCoroutine(): \Generator
/**
* @template Type
*
* @param ExtractorInterface<Type> $extractor
* @param StepRejectionInterface<Type> $rejection
* @param ExtractorInterface<Type> $extractor
* @param StepRejectionInterface<Type|null> $rejection
*/
public function extract(
StepCodeInterface $stepCode,
Expand All @@ -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<int, mixed> $iterator */
$iterator = new \ArrayIterator($extract);
} elseif ($extract instanceof \Iterator) {

Check warning on line 78 in src/Pipeline.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "InstanceOf_": --- Original +++ New @@ @@ if (\is_array($extract)) { /** @var \ArrayIterator<int, mixed> $iterator */ $iterator = new \ArrayIterator($extract); - } elseif ($extract instanceof \Iterator) { + } elseif (true) { /** @var \Iterator<int, mixed> $iterator */ $iterator = $extract; } elseif ($extract instanceof \Traversable) {

Check warning on line 78 in src/Pipeline.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "InstanceOf_": --- Original +++ New @@ @@ if (\is_array($extract)) { /** @var \ArrayIterator<int, mixed> $iterator */ $iterator = new \ArrayIterator($extract); - } elseif ($extract instanceof \Iterator) { + } elseif (false) { /** @var \Iterator<int, mixed> $iterator */ $iterator = $extract; } elseif ($extract instanceof \Traversable) {
$this->source->append(
$this->runner->run(
$extract,
$this->passThroughCoroutine(),
$rejection,
$state,
)
);
/** @var \Iterator<int, mixed> $iterator */
$iterator = $extract;
} elseif ($extract instanceof \Traversable) {
$this->source->append(
$this->runner->run(
new \IteratorIterator($extract),
$this->passThroughCoroutine(),
$rejection,
$state,
)
);
/** @var \IteratorIterator<int, mixed, \Iterator<int, mixed>> $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));

Check failure on line 88 in src/Pipeline.php

View workflow job for this annotation

GitHub Actions / phpstan

Parameter #3 $rejection of method Kiboko\Contract\Pipeline\PipelineRunnerInterface::run() expects Kiboko\Contract\Pipeline\StepRejectionInterface<mixed>, Kiboko\Contract\Pipeline\StepRejectionInterface<Type|null> given.

return $this;
}

Expand All @@ -109,7 +95,7 @@ public function extract(
* @template OutputType
*
* @param TransformerInterface<InputType, OutputType> $transformer
* @param StepRejectionInterface<InputType> $rejection
* @param StepRejectionInterface<InputType|null> $rejection
*/
public function transform(
StepCodeInterface $stepCode,
Expand All @@ -118,6 +104,7 @@ public function transform(
StepStateInterface $state,
): TransformingInterface {
if ($transformer instanceof FlushableInterface) {
/** @var \AppendIterator<int, mixed, \Iterator<int, mixed>> $iterator */
$iterator = new \AppendIterator();

$iterator->append(
Expand Down Expand Up @@ -158,7 +145,7 @@ public function transform(
* @template OutputType
*
* @param LoaderInterface<InputType, OutputType> $loader
* @param StepRejectionInterface<InputType> $rejection
* @param StepRejectionInterface<InputType|null> $rejection
*/
public function load(
StepCodeInterface $stepCode,
Expand Down
10 changes: 0 additions & 10 deletions src/PipelineRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,6 @@ public function __construct(
private readonly LogLevel|string $rejectionLevel = LogLevel::WARNING
) {}

/**
* @template InputType
* @template OutputType
*
* @param \Iterator<int<0, max>, InputType|null> $source
* @param \Generator<int, ResultBucketInterface<OutputType>|AcceptanceResultBucketInterface<InputType>|RejectionResultBucketInterface<InputType>|null, InputType, void> $coroutine
* @param StepRejectionInterface<InputType> $rejection
*
* @return \Iterator<int<0, max>, ResultBucketInterface<OutputType>>
*/
public function run(
\Iterator $source,
\Generator $coroutine,
Expand Down
4 changes: 1 addition & 3 deletions src/Transformer/BatchingTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ public function transform(): \Generator
public function flush(): ResultBucketInterface
{
if (\count($this->batch) <= 0) {
/** @var EmptyResultBucket<OutputType> $bucket */
$bucket = new EmptyResultBucket();
return $bucket;
return new EmptyResultBucket();
}

/* @phpstan-ignore-next-line */
Expand Down
4 changes: 3 additions & 1 deletion src/Transformer/FilterTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ public function transform(): \Generator
continue;
}

$line = yield new AcceptanceResultBucket($line);
/** @var AcceptanceResultBucket<Type> $bucket */
$bucket = new AcceptanceResultBucket($line);
$line = yield $bucket;
}
}
}
2 changes: 0 additions & 2 deletions src/UnexpectedYieldedValueType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Kiboko\Component\Pipeline;

use Kiboko\Contract\Bucket\ResultBucketInterface;

/**
* @template InputType
* @template OutputType
Expand Down

0 comments on commit e2b9c62

Please sign in to comment.