Skip to content

Commit

Permalink
CS Fixing classes
Browse files Browse the repository at this point in the history
  • Loading branch information
gplanchat committed Nov 14, 2023
1 parent d1e6ba2 commit e61319b
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 55 deletions.
5 changes: 2 additions & 3 deletions src/Extractor/ArrayExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@

/**
* @template Type of non-empty-array<array-key, mixed>|object
*
* @implements ExtractorInterface<Type>
*/
class ArrayExtractor implements ExtractorInterface
{
/** @param non-empty-array<array-key, Type> $data */
public function __construct(private readonly array $data)
{
}
public function __construct(private readonly array $data) {}

/**
* @return \Generator
Expand Down
5 changes: 2 additions & 3 deletions src/Extractor/IteratorExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@

/**
* @template Type of non-empty-array<array-key, mixed>|object
*
* @implements ExtractorInterface<Type>
*/
class IteratorExtractor implements ExtractorInterface
{
/** @param \Traversable<mixed, Type> $traversable */
public function __construct(private readonly \Traversable $traversable)
{
}
public function __construct(private readonly \Traversable $traversable) {}

/**
* @return \Generator
Expand Down
2 changes: 1 addition & 1 deletion src/GeneratorWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function valid(\Iterator ...$iterators): bool
}

/**
* @param Type $value
* @param Type $value
* @param \Generator<int<0, max>, ResultBucketInterface<Type>, Type, void> ...$generators
*/
public function send($value, \Generator ...$generators): \Generator
Expand Down
8 changes: 3 additions & 5 deletions src/Loader/LogLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@
*/
final readonly class LogLoader implements LoaderInterface
{
public function __construct(private LoggerInterface $logger, private string $logLevel = LogLevel::DEBUG)
{
}
public function __construct(private LoggerInterface $logger, private string $logLevel = LogLevel::DEBUG) {}

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

Check failure on line 23 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 23 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 23 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 25 in src/Loader/LogLoader.php

View workflow job for this annotation

GitHub Actions / phpstan

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

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

View workflow job for this annotation

GitHub Actions / phpstan

Generator expects key type int<0, max>, int given.
/** @phpstan-ignore-next-line */
/* @phpstan-ignore-next-line */
while (true) {
if ($line === null) {
if (null === $line) {
$line = yield new EmptyResultBucket();

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

View workflow job for this annotation

GitHub Actions / phpstan

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

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

View workflow job for this annotation

GitHub Actions / phpstan

Generator expects key type int<0, max>, int given.
continue;
}
Expand Down
5 changes: 2 additions & 3 deletions src/Loader/StreamLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public function __construct($stream)
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<0, 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<0, max>, int given.
/** @phpstan-ignore-next-line */
/* @phpstan-ignore-next-line */
while (true) {
if ($line === null) {
if (null === $line) {
$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<0, 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<0, max>, int given.
continue;
}
Expand All @@ -46,7 +46,6 @@ public function load(): \Generator

/**
* @param Type|null $line
* @return string
*/
abstract protected function formatLine(mixed $line): string;
}
11 changes: 5 additions & 6 deletions src/Pipeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Pipeline implements PipelineInterface, WalkableInterface, RunnableInterfac
public function __construct(
private readonly PipelineRunnerInterface $runner,
private readonly StateInterface $state,
?\Iterator $source = null
\Iterator $source = null
) {
$this->source = new \AppendIterator();
$this->source->append($source ?? new \EmptyIterator());

Check warning on line 36 in src/Pipeline.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "Coalesce": --- Original +++ New @@ @@ public function __construct(private readonly PipelineRunnerInterface $runner, private readonly StateInterface $state, \Iterator $source = null) { $this->source = new \AppendIterator(); - $this->source->append($source ?? new \EmptyIterator()); + $this->source->append(new \EmptyIterator() ?? $source); $this->subject = new \NoRewindIterator($this->source); } /**

Check warning on line 36 in src/Pipeline.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ public function __construct(private readonly PipelineRunnerInterface $runner, private readonly StateInterface $state, \Iterator $source = null) { $this->source = new \AppendIterator(); - $this->source->append($source ?? new \EmptyIterator()); + $this->subject = new \NoRewindIterator($this->source); } /**
Expand All @@ -42,7 +42,6 @@ public function __construct(
* @template InputType of non-empty-array<array-key, mixed>|object
*
* @param InputType ...$data
* @return void
*/
public function feed(...$data): void
{
Expand All @@ -52,7 +51,7 @@ public function feed(...$data): void
private function passThroughCoroutine(): \Generator
{
$line = yield;
/** @phpstan-ignore-next-line */
/* @phpstan-ignore-next-line */
while (true) {
$line = yield $line;
}
Expand All @@ -61,7 +60,7 @@ private function passThroughCoroutine(): \Generator
/**
* @template Type of non-empty-array<array-key, mixed>|object
*
* @param ExtractorInterface<Type> $extractor
* @param ExtractorInterface<Type> $extractor
* @param StepRejectionInterface<Type> $rejection
*/
public function extract(
Expand Down Expand Up @@ -110,7 +109,7 @@ public function extract(
* @template OutputType of non-empty-array<array-key, mixed>|object
*
* @param TransformerInterface<InputType, OutputType> $transformer
* @param StepRejectionInterface<InputType> $rejection
* @param StepRejectionInterface<InputType> $rejection
*/
public function transform(
StepCodeInterface $stepCode,
Expand Down Expand Up @@ -159,7 +158,7 @@ public function transform(
* @template OutputType of non-empty-array<array-key, mixed>|object
*
* @param LoaderInterface<InputType, OutputType> $loader
* @param StepRejectionInterface<InputType> $rejection
* @param StepRejectionInterface<InputType> $rejection
*/
public function load(
StepCodeInterface $stepCode,
Expand Down
17 changes: 6 additions & 11 deletions src/PipelineRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@

namespace Kiboko\Component\Pipeline;

use Kiboko\Component\Bucket\RejectionResultBucket;
use Kiboko\Component\Bucket\RejectionWithReasonResultBucket;
use Kiboko\Contract\Bucket\AcceptanceResultBucketInterface;
use Kiboko\Contract\Bucket\RejectionResultBucketInterface;
use Kiboko\Contract\Bucket\ResultBucketInterface;
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;
use Psr\Log\LoggerInterface;
Expand All @@ -23,17 +19,16 @@ class PipelineRunner implements PipelineRunnerInterface
public function __construct(
private readonly LoggerInterface $logger = new NullLogger(),
private readonly LogLevel|string $rejectionLevel = LogLevel::WARNING
) {
}
) {}

/**
* @template InputType of non-empty-array<array-key, mixed>|object
* @template OutputType of non-empty-array<array-key, mixed>|object
*
* @param \Iterator<int<0, max>, InputType|null> $source
* @param \Iterator<int<0, max>, InputType|null> $source
* @param \Generator<int<0, max>, ResultBucketInterface<OutputType>|AcceptanceResultBucketInterface<InputType>|RejectionResultBucketInterface<InputType>|null, InputType, void> $coroutine
* @param StepRejectionInterface<InputType> $rejection
* @param StepStateInterface $state
* @param StepRejectionInterface<InputType> $rejection
*
* @return \Iterator<int<0, max>, ResultBucketInterface<OutputType>>
*/
public function run(
Expand All @@ -59,8 +54,8 @@ public function run(
if ($bucket instanceof RejectionResultBucketInterface) {
$reasons = $bucket->reasons();
foreach ($bucket->walkRejection() as $line) {
if ($reasons !== null) {
$rejection->rejectWithReason($line, implode(PHP_EOL, $reasons));
if (null !== $reasons) {
$rejection->rejectWithReason($line, implode(\PHP_EOL, $reasons));
} else {
$rejection->reject($line);
}
Expand Down
3 changes: 1 addition & 2 deletions src/StepCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
{
private function __construct(
private string $reference,
) {
}
) {}

public static function fromString(string $reference): self
{
Expand Down
14 changes: 7 additions & 7 deletions src/Transformer/BatchingTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,23 @@ class BatchingTransformer implements TransformerInterface, FlushableInterface
*/
public function __construct(
private readonly int $batchSize
) {
}
) {}

/** @return \Generator<int<0, max>, ResultBucketInterface<OutputType>|EmptyResultBucket, InputType|null, void> */
public function transform(): \Generator

Check failure on line 33 in src/Transformer/BatchingTransformer.php

View workflow job for this annotation

GitHub Actions / phpstan

Method Kiboko\Component\Pipeline\Transformer\BatchingTransformer::transform() return type with generic class Kiboko\Component\Bucket\EmptyResultBucket does not specify its types: Type
{
$this->batch = [];

$line = yield new EmptyResultBucket();
/** @phpstan-ignore-next-line */
/* @phpstan-ignore-next-line */
while (true) {
if ($line === null) {
if (null === $line) {
$line = yield new EmptyResultBucket();
continue;
}
$this->batch[] = $line;

if (count($this->batch) >= $this->batchSize) {
if (\count($this->batch) >= $this->batchSize) {
/** @phpstan-ignore-next-line */
$line = yield new AcceptanceResultBucket($this->batch);
$this->batch = [];
Expand All @@ -58,10 +57,11 @@ public function transform(): \Generator
/** @return AcceptanceResultBucket<OutputType>|EmptyResultBucket */
public function flush(): ResultBucketInterface
{
if (count($this->batch) <= 0) {
if (\count($this->batch) <= 0) {
return new EmptyResultBucket();
}
/** @phpstan-ignore-next-line */

/* @phpstan-ignore-next-line */
return new AcceptanceResultBucket($this->batch);
}
}
6 changes: 3 additions & 3 deletions src/Transformer/CallableTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/
class CallableTransformer implements TransformerInterface
{
/** @var callable(InputType|null $item): OutputType */
/** @var callable(InputType|null): OutputType */
private $callback;

/**
Expand All @@ -36,9 +36,9 @@ public function transform(): \Generator
$callback = $this->callback;

$line = yield new EmptyResultBucket();
/** @phpstan-ignore-next-line */
/* @phpstan-ignore-next-line */
while (true) {
if ($line === null) {
if (null === $line) {
$line = yield new EmptyResultBucket();
continue;
}
Expand Down
5 changes: 2 additions & 3 deletions src/Transformer/ColumnTrimTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@ class ColumnTrimTransformer implements TransformerInterface
/** @param list<string> $columnsToTrim */
public function __construct(
private readonly array $columnsToTrim
) {
}
) {}

/** @return \Generator<int<0, max>, AcceptanceResultBucket<OutputType>|EmptyResultBucket, InputType|null, void> */
public function transform(): \Generator
{
$line = yield new EmptyResultBucket();
/** @phpstan-ignore-next-line */
/* @phpstan-ignore-next-line */
while (true) {
if (null === $line) {
$line = yield new EmptyResultBucket();
Expand Down
4 changes: 2 additions & 2 deletions src/Transformer/FilterTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
class FilterTransformer implements TransformerInterface
{
/** @var callable(Type $item): bool */
/** @var callable(Type): bool */
private $callback;

/** @param callable(Type $item): bool $callback */
Expand All @@ -33,7 +33,7 @@ public function transform(): \Generator
$callback = $this->callback;

$line = yield new EmptyResultBucket();
/** @phpstan-ignore-next-line */
/* @phpstan-ignore-next-line */
while (true) {
if (null === $line || !$callback($line)) {
$line = yield new EmptyResultBucket();
Expand Down
11 changes: 5 additions & 6 deletions src/UnexpectedYieldedValueType.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function __construct(
private readonly \Generator $coroutine,
string $message = '',
int $code = 0,
?\Throwable $previous = null
\Throwable $previous = null
) {
parent::__construct($message, $code, $previous);
}
Expand All @@ -28,12 +28,11 @@ public function getCoroutine(): \Generator

/**
* @param \Generator<int<0, max>, ResultBucketInterface<OutputType>, InputType, void> $actual
* @param list<string> $expectedTypes
* @param mixed $actual
* @param list<string> $expectedTypes
*
* @return UnexpectedYieldedValueType<InputType, OutputType>
*/
public static function expectingTypes(\Generator $coroutine, array $expectedTypes, $actual, int $code = 0, ?\Throwable $previous = null): self
public static function expectingTypes(\Generator $coroutine, array $expectedTypes, $actual, int $code = 0, \Throwable $previous = null): self
{
try {
$re = new \ReflectionGenerator($coroutine);
Expand All @@ -48,7 +47,7 @@ public static function expectingTypes(\Generator $coroutine, array $expectedType
$executionFile = $re->getExecutingFile();
$executionLine = $re->getExecutingLine();

/** @phpstan-ignore-next-line */
/* @phpstan-ignore-next-line */
return new self(
$coroutine,
strtr(
Expand All @@ -65,7 +64,7 @@ public static function expectingTypes(\Generator $coroutine, array $expectedType
$previous
);
} catch (\ReflectionException) {
/** @phpstan-ignore-next-line */
/* @phpstan-ignore-next-line */
return new self(
$coroutine,
strtr(
Expand Down

0 comments on commit e61319b

Please sign in to comment.