Skip to content

Commit 3400efb

Browse files
committed
Updated PHPStan rules level 4
1 parent a5f72f8 commit 3400efb

8 files changed

+87
-48
lines changed

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Pipeline implementation
2+
===
3+
4+
This package brings an implementation for the pipeline component, aimed at providing an Extract-Transform-Load pattern,
5+
with logging, line rejections and execution states.
6+
7+
8+
[![Quality](https://github.com/php-etl/pipeline/actions/workflows/quality.yaml/badge.svg)](https://github.com/php-etl/pipeline/actions/workflows/quality.yaml)
9+
[![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)
10+
[![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)
11+
[![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)
12+
![PHP](https://img.shields.io/packagist/php-v/php-etl/pipeline)
13+
14+
Documentation
15+
---
16+
17+
[See full Documentation](https://php-etl.github.io/documentation)
18+
19+

composer.lock

Lines changed: 15 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Loader/LogLoader.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
namespace Kiboko\Component\Pipeline\Loader;
44

55
use Kiboko\Component\Bucket\AcceptanceResultBucket;
6+
use Kiboko\Component\Bucket\EmptyResultBucket;
67
use Kiboko\Contract\Pipeline\LoaderInterface;
78
use Psr\Log\LoggerInterface;
89
use Psr\Log\LogLevel;
910

11+
/**
12+
* @template Type
13+
* @template-implements LoaderInterface<Type>
14+
*/
1015
final class LogLoader implements LoaderInterface
1116
{
1217
/** @var LoggerInterface */
@@ -20,9 +25,10 @@ public function __construct(LoggerInterface $logger, string $logLevel = LogLevel
2025
$this->logLevel = $logLevel;
2126
}
2227

28+
/** @return \Generator<mixed, AcceptanceResultBucket<Type|null>|EmptyResultBucket, null|Type, void> */
2329
public function load(): \Generator
2430
{
25-
$line = yield;
31+
$line = yield new EmptyResultBucket();
2632
do {
2733
$this->logger->log($this->logLevel, var_export($line, true));
2834
} while ($line = yield new AcceptanceResultBucket($line));

src/Loader/StreamLoader.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33
namespace Kiboko\Component\Pipeline\Loader;
44

55
use Kiboko\Component\Bucket\AcceptanceResultBucket;
6+
use Kiboko\Component\Bucket\EmptyResultBucket;
67
use Kiboko\Contract\Pipeline\LoaderInterface;
78

9+
/**
10+
* @template Type
11+
* @template-implements LoaderInterface<Type>
12+
*/
813
abstract class StreamLoader implements LoaderInterface
914
{
1015
/** @var resource */
1116
private $stream;
1217

13-
/**
14-
* @param resource $stream
15-
*/
18+
/** @param resource $stream */
1619
public function __construct($stream)
1720
{
1821
if (!is_resource($stream) || get_resource_type($stream) !== 'stream') {
@@ -24,12 +27,14 @@ public function __construct($stream)
2427
$this->stream = $stream;
2528
}
2629

30+
/** @return \Generator<mixed, AcceptanceResultBucket<Type|null>|EmptyResultBucket, null|Type, void> */
2731
public function load(): \Generator
2832
{
29-
$line = yield;
30-
do {
33+
$line = yield new EmptyResultBucket();
34+
while (true) {
3135
fwrite($this->stream, $this->formatLine($line));
32-
} while ($line = yield new AcceptanceResultBucket($line));
36+
$line = yield new AcceptanceResultBucket($line);
37+
}
3338
}
3439

3540
abstract protected function formatLine($line);

src/Transformer/BatchingTransformer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Kiboko\Contract\Pipeline\FlushableInterface;
99
use Kiboko\Contract\Pipeline\TransformerInterface;
1010

11+
/** @template Type */
1112
class BatchingTransformer implements TransformerInterface, FlushableInterface
1213
{
1314
private ResultBucketInterface $bucket;
@@ -17,12 +18,13 @@ public function __construct(private int $batchSize)
1718
$this->bucket = new EmptyResultBucket();
1819
}
1920

21+
/** @return \Generator<mixed, AcceptanceAppendableResultBucket<Type>|EmptyResultBucket, null|Type, void> */
2022
public function transform(): \Generator
2123
{
2224
$this->bucket = new AcceptanceAppendableResultBucket();
2325
$itemCount = 0;
2426

25-
$line = yield;
27+
$line = yield new EmptyResultBucket();
2628
while (true) {
2729
$this->bucket->append($line);
2830

src/Transformer/CallableTransformer.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,26 @@
33
namespace Kiboko\Component\Pipeline\Transformer;
44

55
use Kiboko\Component\Bucket\AcceptanceResultBucket;
6+
use Kiboko\Component\Bucket\EmptyResultBucket;
67
use Kiboko\Contract\Pipeline\TransformerInterface;
78

9+
/** @template Type */
810
class CallableTransformer implements TransformerInterface
911
{
10-
/**
11-
* @var callable
12-
*/
12+
/** @var callable */
1313
private $callback;
1414

15-
/**
16-
* @param callable $callback
17-
*/
15+
/** @param callable $callback */
1816
public function __construct(
1917
callable $callback
2018
) {
2119
$this->callback = $callback;
2220
}
2321

22+
/** @return \Generator<mixed, AcceptanceResultBucket<Type>|EmptyResultBucket, null|Type, void> */
2423
public function transform(): \Generator
2524
{
26-
$line = yield;
25+
$line = yield new EmptyResultBucket();
2726
do {
2827
} while ($line = yield new AcceptanceResultBucket(($this->callback)($line)));
2928
}

src/Transformer/ColumnTrimTransformer.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,38 @@
33
namespace Kiboko\Component\Pipeline\Transformer;
44

55
use Kiboko\Component\Bucket\AcceptanceResultBucket;
6+
use Kiboko\Component\Bucket\EmptyResultBucket;
67
use Kiboko\Contract\Pipeline\TransformerInterface;
78

9+
/**
10+
* @template Type
11+
* @template-implements TransformerInterface<array>
12+
*/
813
class ColumnTrimTransformer implements TransformerInterface
914
{
10-
/**
11-
* @var array
12-
*/
13-
private $columnsToTrim;
14-
15-
/**
16-
* @param array $columnsToTrim
17-
*/
18-
public function __construct(array $columnsToTrim)
19-
{
20-
$this->columnsToTrim = $columnsToTrim;
15+
/** @param list<string> $columnsToTrim */
16+
public function __construct(
17+
private array $columnsToTrim
18+
) {
2119
}
2220

21+
/** @return \Generator<mixed, AcceptanceResultBucket<Type>|EmptyResultBucket, null|Type, void> */
2322
public function transform(): \Generator
2423
{
25-
$line = yield;
26-
do {
24+
$line = yield new EmptyResultBucket();
25+
while (true) {
26+
if ($line === null) {
27+
$line = yield new EmptyResultBucket();
28+
continue;
29+
}
2730
foreach ($this->columnsToTrim as $column) {
2831
if (!isset($line[$column])) {
2932
continue;
3033
}
3134

3235
$line[$column] = trim($line[$column]);
3336
}
34-
} while ($line = yield new AcceptanceResultBucket($line));
37+
$line = yield new AcceptanceResultBucket($line);
38+
}
3539
}
3640
}

src/Transformer/FilterTransformer.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@
66
use Kiboko\Component\Bucket\EmptyResultBucket;
77
use Kiboko\Contract\Pipeline\TransformerInterface;
88

9+
/**
10+
* @template Type
11+
* @template-implements TransformerInterface<Type>
12+
*/
913
class FilterTransformer implements TransformerInterface
1014
{
11-
/**
12-
* @var callable
13-
*/
15+
/** @var callable */
1416
private $callback;
1517

16-
/**
17-
* @param $callback
18-
*/
1918
public function __construct(callable $callback)
2019
{
2120
$this->callback = $callback;
2221
}
2322

23+
/** @return \Generator<mixed, AcceptanceResultBucket<Type>|EmptyResultBucket, null|Type, void> */
2424
public function transform(): \Generator
2525
{
2626
$callback = $this->callback;
2727

28-
$line = yield;
28+
$line = yield new EmptyResultBucket();
2929
while (true) {
30-
if (!$callback($line)) {
30+
if ($line === null || !$callback($line)) {
3131
$line = yield new EmptyResultBucket();
3232
continue;
3333
}

0 commit comments

Comments
 (0)