Skip to content

Commit

Permalink
Fixing PHPStan level 9 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gplanchat committed Nov 13, 2023
1 parent 2b8bb81 commit 000076d
Show file tree
Hide file tree
Showing 18 changed files with 466 additions and 694 deletions.
768 changes: 282 additions & 486 deletions composer.lock

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/Extractor/ArrayExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@

use Kiboko\Contract\Pipeline\ExtractorInterface;

/**
* @template Type
* @implements ExtractorInterface<Type>
*/
class ArrayExtractor implements ExtractorInterface
{
/** @param non-empty-array<array-key, Type> $data */
public function __construct(private readonly array $data)
{
}
Expand Down
6 changes: 5 additions & 1 deletion src/Extractor/IteratorExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

namespace Kiboko\Component\Pipeline\Extractor;

use Kiboko\Component\Bucket\AcceptanceResultBucket;
use Kiboko\Contract\Pipeline\ExtractorInterface;

/**
* @template Type
* @implements ExtractorInterface<Type>
*/
class IteratorExtractor implements ExtractorInterface
{
/** @param \Traversable<mixed, Type> $traversable */
public function __construct(private readonly \Traversable $traversable)
{
}
Expand Down
12 changes: 12 additions & 0 deletions src/GeneratorWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,30 @@

namespace Kiboko\Component\Pipeline;

use Kiboko\Contract\Bucket\ResultBucketInterface;

/**
* @template Type
*/
class GeneratorWrapper
{
/** @param \Iterator<mixed, mixed> ...$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<mixed, mixed> ...$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<mixed, mixed> ...$iterators */
}
}

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

/** @param \Iterator<mixed, mixed> ...$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<mixed, mixed> ...$iterators */ public function valid(\Iterator ...$iterators) : bool { - foreach ($iterators as $iterator) { + foreach (array() as $iterator) { if (!$iterator->valid()) { return false; }
Expand All @@ -31,6 +39,10 @@ public function valid(\Iterator ...$iterators): bool
return true;
}

/**
* @param Type $value
* @param \Generator<array-key, ResultBucketInterface<Type>, Type|null, void> ...$generators
*/
public function send($value, \Generator ...$generators): \Generator
{
foreach ($generators as $generator) {
Expand Down
137 changes: 0 additions & 137 deletions src/IteratorLoggingWrapper.php

This file was deleted.

10 changes: 9 additions & 1 deletion src/Loader/DebugLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@

namespace Kiboko\Component\Pipeline\Loader;

/**
* @template Type
*
* @extends StreamLoader<Type>
*/
final class DebugLoader extends StreamLoader
{
protected function formatLine($line)
/**
* @param Type|null $line
*/
protected function formatLine(mixed $line): string
{
return var_export($line, true).\PHP_EOL;
}
Expand Down
10 changes: 9 additions & 1 deletion src/Loader/JSONStreamLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@

namespace Kiboko\Component\Pipeline\Loader;

/**
* @template Type
*
* @extends StreamLoader<Type>
*/
final class JSONStreamLoader extends StreamLoader
{
protected function formatLine($line)
/**
* @param Type|null $line
*/
protected function formatLine(mixed $line): string
{
return json_encode($line, \JSON_THROW_ON_ERROR).\PHP_EOL;
}
Expand Down
8 changes: 5 additions & 3 deletions src/Loader/LogLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
/**
* @template Type
*
* @template-implements LoaderInterface<Type>
* @implements LoaderInterface<Type, Type>
*/
final readonly class LogLoader implements LoaderInterface
{
Expand All @@ -25,8 +25,10 @@ public function __construct(private LoggerInterface $logger, private string $log
public function load(): \Generator
{
$line = yield new EmptyResultBucket();
do {
/** @phpstan-ignore-next-line */
while (true) {

Check failure on line 29 in src/Loader/LogLoader.php

View workflow job for this annotation

GitHub Actions / phpstan

No error to ignore is reported on line 29.
$this->logger->log($this->logLevel, var_export($line, true));
} while ($line = yield new AcceptanceResultBucket($line));
$line = yield new AcceptanceResultBucket($line);
}
}
}
10 changes: 9 additions & 1 deletion src/Loader/StderrLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@

namespace Kiboko\Component\Pipeline\Loader;

/**
* @template Type
*
* @extends StreamLoader<Type>
*/
final class StderrLoader extends StreamLoader
{
public function __construct()
{
parent::__construct(\STDOUT);
}

protected function formatLine($line)
/**
* @param Type|null $line
*/
protected function formatLine(mixed $line): string
{
return var_export($line, true).\PHP_EOL;
}
Expand Down
10 changes: 9 additions & 1 deletion src/Loader/StdoutLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,22 @@

namespace Kiboko\Component\Pipeline\Loader;

/**
* @template Type
*
* @extends StreamLoader<Type>
*/
final class StdoutLoader extends StreamLoader
{
public function __construct()
{
parent::__construct(\STDOUT);
}

protected function formatLine($line)
/**
* @param Type|null $line
*/
protected function formatLine(mixed $line): string
{
return var_export($line, true).\PHP_EOL;
}
Expand Down
11 changes: 8 additions & 3 deletions src/Loader/StreamLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* @template Type
*
* @template-implements LoaderInterface<Type>
* @implements LoaderInterface<Type, Type>
*/
abstract class StreamLoader implements LoaderInterface
{
Expand All @@ -32,11 +32,16 @@ public function __construct($stream)
public function load(): \Generator
{
$line = yield new EmptyResultBucket();
/** @phpstan-ignore-next-line */
while (true) {

Check failure on line 36 in src/Loader/StreamLoader.php

View workflow job for this annotation

GitHub Actions / phpstan

No error to ignore is reported on line 36.
fwrite($this->stream, (string) $this->formatLine($line));
fwrite($this->stream, $this->formatLine($line));
$line = yield new AcceptanceResultBucket($line);
}
}

abstract protected function formatLine($line);
/**
* @param Type|null $line
* @return string
*/
abstract protected function formatLine(mixed $line): string;
}
8 changes: 7 additions & 1 deletion src/Pipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@
class Pipeline implements PipelineInterface, WalkableInterface, RunnableInterface
{
private readonly \AppendIterator $source;
/** @var iterable<mixed>|\NoRewindIterator */
private iterable $subject;

/**
* @param PipelineRunnerInterface<mixed> $runner
*/
public function __construct(
private readonly PipelineRunnerInterface $runner,
private readonly StateInterface $state,
Expand All @@ -45,7 +49,9 @@ public function feed(...$data): void
private function passThroughCoroutine(): \Generator
{
$line = yield;
while ($line = yield $line);
while (true) {

Check failure on line 52 in src/Pipeline.php

View workflow job for this annotation

GitHub Actions / phpstan

While loop condition is always true.

Check failure on line 52 in src/Pipeline.php

View workflow job for this annotation

GitHub Actions / phpstan

While loop condition is always true.

Check failure on line 52 in src/Pipeline.php

View workflow job for this annotation

GitHub Actions / phpstan

While loop condition is always true.

Check failure on line 52 in src/Pipeline.php

View workflow job for this annotation

GitHub Actions / phpstan

While loop condition is always true.
$line = yield $line;
}
}

public function extract(
Expand Down
Loading

0 comments on commit 000076d

Please sign in to comment.