Skip to content

Commit

Permalink
Fixing PHPStan level 4 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gplanchat committed Nov 14, 2023
1 parent 141ef98 commit f5f87d2
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 84 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"php": "^8.2",
"psr/log": "^3.0",
"php-etl/bucket": "*",
"php-etl/pipeline-contracts": "0.5.*",
"php-etl/bucket-contracts": "0.2.*"
"php-etl/pipeline-contracts": "0.5.*"
},
"require-dev": {
"phpunit/php-invoker": "^4.0",
Expand Down
56 changes: 29 additions & 27 deletions composer.lock

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

2 changes: 1 addition & 1 deletion src/Extractor/ArrayExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Kiboko\Contract\Pipeline\ExtractorInterface;

/**
* @template Type
* @template Type of non-empty-array<array-key, mixed>|object
* @implements ExtractorInterface<Type>
*/
class ArrayExtractor implements ExtractorInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Extractor/IteratorExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Kiboko\Contract\Pipeline\ExtractorInterface;

/**
* @template Type
* @template Type of non-empty-array<array-key, mixed>|object
* @implements ExtractorInterface<Type>
*/
class IteratorExtractor implements ExtractorInterface
Expand Down
10 changes: 5 additions & 5 deletions src/GeneratorWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@
use Kiboko\Contract\Bucket\ResultBucketInterface;

/**
* @template Type
* @template Type of non-empty-array<array-key, mixed>|object
*/
class GeneratorWrapper
{
/** @param \Iterator<array-key, Type> ...$iterators */
/** @param \Iterator<positive-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<positive-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<positive-int, Type> ...$iterators */
}
}

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

/** @param \Iterator<array-key, Type> ...$iterators */
/** @param \Iterator<positive-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<positive-int, Type> ...$iterators */ public function valid(\Iterator ...$iterators) : bool { - foreach ($iterators as $iterator) { + foreach (array() as $iterator) { if (!$iterator->valid()) { return false; }
Expand All @@ -41,7 +41,7 @@ public function valid(\Iterator ...$iterators): bool

/**
* @param Type $value
* @param \Generator<array-key, ResultBucketInterface<Type>, Type, void> ...$generators
* @param \Generator<positive-int, ResultBucketInterface<Type>, Type, void> ...$generators
*/
public function send($value, \Generator ...$generators): \Generator
{
Expand Down
2 changes: 1 addition & 1 deletion src/Loader/DebugLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Kiboko\Component\Pipeline\Loader;

/**
* @template Type
* @template Type of non-empty-array<array-key, mixed>|object
*
* @extends StreamLoader<Type>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Loader/JSONStreamLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Kiboko\Component\Pipeline\Loader;

/**
* @template Type
* @template Type of non-empty-array<array-key, mixed>|object
*
* @extends StreamLoader<Type>
*/
Expand Down
9 changes: 7 additions & 2 deletions src/Loader/LogLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Psr\Log\LogLevel;

/**
* @template Type
* @template Type of non-empty-array<array-key, mixed>|object
*
* @implements LoaderInterface<Type, Type>
*/
Expand All @@ -21,12 +21,17 @@ public function __construct(private LoggerInterface $logger, private string $log
{
}

/** @return \Generator<mixed, AcceptanceResultBucket<Type|null>|EmptyResultBucket, Type|null, void> */
/** @return \Generator<positive-int, AcceptanceResultBucket<Type>|EmptyResultBucket, Type|null, void> */
public function load(): \Generator

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

View workflow job for this annotation

GitHub Actions / phpstan

Method Kiboko\Component\Pipeline\Loader\LogLoader::load() return type with generic class Kiboko\Component\Bucket\EmptyResultBucket does not specify its types: Type

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

View workflow job for this annotation

GitHub Actions / phpstan

Method Kiboko\Component\Pipeline\Loader\LogLoader::load() return type with generic class Kiboko\Component\Bucket\EmptyResultBucket does not specify its types: Type

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

View workflow job for this annotation

GitHub Actions / phpstan

Method Kiboko\Component\Pipeline\Loader\LogLoader::load() return type with generic class Kiboko\Component\Bucket\EmptyResultBucket does not specify its types: Type
{
$line = yield new EmptyResultBucket();

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

View workflow job for this annotation

GitHub Actions / phpstan

Generator expects key type int<1, max>, int given.

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

View workflow job for this annotation

GitHub Actions / phpstan

Generator expects key type int<1, max>, int given.
/** @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.
if ($line === null) {
$line = yield new EmptyResultBucket();

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

View workflow job for this annotation

GitHub Actions / phpstan

Generator expects key type int<1, max>, int given.

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

View workflow job for this annotation

GitHub Actions / phpstan

Generator expects key type int<1, max>, int given.
continue;
}

$this->logger->log($this->logLevel, var_export($line, true));
$line = yield new AcceptanceResultBucket($line);

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

View workflow job for this annotation

GitHub Actions / phpstan

Generator expects key type int<1, max>, int given.

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

View workflow job for this annotation

GitHub Actions / phpstan

Generator expects key type int<1, max>, int given.
}
Expand Down
2 changes: 1 addition & 1 deletion src/Loader/StderrLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Kiboko\Component\Pipeline\Loader;

/**
* @template Type
* @template Type of non-empty-array<array-key, mixed>|object
*
* @extends StreamLoader<Type>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Loader/StdoutLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Kiboko\Component\Pipeline\Loader;

/**
* @template Type
* @template Type of non-empty-array<array-key, mixed>|object
*
* @extends StreamLoader<Type>
*/
Expand Down
9 changes: 7 additions & 2 deletions src/Loader/StreamLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Kiboko\Contract\Pipeline\LoaderInterface;

/**
* @template Type
* @template Type of non-empty-array<array-key, mixed>|object
*
* @implements LoaderInterface<Type, Type>
*/
Expand All @@ -28,12 +28,17 @@ public function __construct($stream)
$this->stream = $stream;
}

/** @return \Generator<mixed, AcceptanceResultBucket<Type|null>|EmptyResultBucket, Type|null, void> */
/** @return \Generator<positive-int, AcceptanceResultBucket<Type>|EmptyResultBucket, Type|null, void> */
public function load(): \Generator

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

View workflow job for this annotation

GitHub Actions / phpstan

Method Kiboko\Component\Pipeline\Loader\StreamLoader::load() return type with generic class Kiboko\Component\Bucket\EmptyResultBucket does not specify its types: Type

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

View workflow job for this annotation

GitHub Actions / phpstan

Method Kiboko\Component\Pipeline\Loader\StreamLoader::load() return type with generic class Kiboko\Component\Bucket\EmptyResultBucket does not specify its types: Type

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

View workflow job for this annotation

GitHub Actions / phpstan

Method Kiboko\Component\Pipeline\Loader\StreamLoader::load() return type with generic class Kiboko\Component\Bucket\EmptyResultBucket does not specify its types: Type
{
$line = yield new EmptyResultBucket();

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

View workflow job for this annotation

GitHub Actions / phpstan

Generator expects key type int<1, max>, int given.

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

View workflow job for this annotation

GitHub Actions / phpstan

Generator expects key type int<1, max>, int given.
/** @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.
if ($line === null) {
$line = yield new EmptyResultBucket();

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

View workflow job for this annotation

GitHub Actions / phpstan

Generator expects key type int<1, max>, int given.

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

View workflow job for this annotation

GitHub Actions / phpstan

Generator expects key type int<1, max>, int given.
continue;
}

fwrite($this->stream, $this->formatLine($line));
$line = yield new AcceptanceResultBucket($line);

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

View workflow job for this annotation

GitHub Actions / phpstan

Generator expects key type int<1, max>, int given.

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

View workflow job for this annotation

GitHub Actions / phpstan

Generator expects key type int<1, max>, int given.
}
Expand Down
Loading

0 comments on commit f5f87d2

Please sign in to comment.