Skip to content

Commit

Permalink
Merge pull request #3 from php-etl/feature/update-contracts
Browse files Browse the repository at this point in the history
Updated php-etl contract versions
  • Loading branch information
gplanchat authored Nov 22, 2023
2 parents 5437a58 + dded8ed commit 9bf4a09
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 101 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/infection.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ jobs:

- name: Infection
run: |
wget -q https://github.com/infection/infection/releases/download/0.26.18/infection.phar
wget -q https://github.com/infection/infection/releases/download/0.26.18/infection.phar.asc
wget -q https://github.com/infection/infection/releases/download/0.27.0/infection.phar
wget -q https://github.com/infection/infection/releases/download/0.27.0/infection.phar.asc
chmod +x infection.phar
./infection.phar
Expand Down
23 changes: 0 additions & 23 deletions .github/workflows/phpstan-5.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/phpstan-6.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: PHPStan level 6
on: push
jobs:
phpstan:
phpstan-6:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpstan-7.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: PHPStan level 7
on: push
jobs:
phpstan:
phpstan-7:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpstan-8.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: PHPStan level 8
on: push
jobs:
phpstan:
phpstan-8:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
36 changes: 18 additions & 18 deletions .github/workflows/quality.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Quality (PHPStan lvl 4)
name: Quality (PHPStan lvl 5)
on: push
jobs:
cs-fixer:
Expand All @@ -17,20 +17,20 @@ jobs:
phpstan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: '**/vendor'
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- uses: php-actions/composer@v6
with:
args: --prefer-dist
php_version: '8.2'

- name: PHPStan
uses: php-actions/phpstan@v3
with:
path: src/
level: 4
- uses: actions/checkout@v3
- uses: actions/cache@v3
with:
path: '**/vendor'
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- uses: php-actions/composer@v6
with:
args: --prefer-dist
php_version: '8.2'
- name: PHPStan
uses: php-actions/phpstan@v3
with:
path: src/
level: 5
php_version: '8.2'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This package brings tools to read and write JSON-LD files in a pipeline.


[![Quality](https://github.com/php-etl/json-flow/actions/workflows/quality.yaml/badge.svg)](https://github.com/php-etl/json-flow/actions/workflows/quality.yaml)
[![PHPStan level 5](https://github.com/php-etl/json-flow/actions/workflows/phpstan-5.yaml/badge.svg)](https://github.com/php-etl/json-flow/actions/workflows/phpstan-5.yaml)
[![PHPStan level 6](https://github.com/php-etl/json-flow/actions/workflows/phpstan-6.yaml/badge.svg)](https://github.com/php-etl/json-flow/actions/workflows/phpstan-6.yaml)
[![PHPStan level 7](https://github.com/php-etl/json-flow/actions/workflows/phpstan-7.yaml/badge.svg)](https://github.com/php-etl/json-flow/actions/workflows/phpstan-7.yaml)
[![PHPStan level 8](https://github.com/php-etl/json-flow/actions/workflows/phpstan-8.yaml/badge.svg)](https://github.com/php-etl/json-flow/actions/workflows/phpstan-8.yaml)
![PHP](https://img.shields.io/packagist/php-v/php-etl/json-flow)
Expand Down
45 changes: 15 additions & 30 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,33 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd"
backupGlobals="true"
colors="false"
processIsolation="false"
stopOnError="false"
stopOnFailure="false"
stopOnIncomplete="false"
stopOnSkipped="false"
stopOnRisky="false"
timeoutForSmallTests="1"
timeoutForMediumTests="10"
timeoutForLargeTests="60"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false"
requireCoverageMetadata="false">
<testsuites>
<testsuite name="Functional tests">
<directory>tests/</directory>
</testsuite>
</testsuites>
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<php>
<ini name="allow_url_include" value="1"/>
</php>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd" backupGlobals="true" colors="false" processIsolation="false" stopOnError="false" stopOnFailure="false" stopOnIncomplete="false" stopOnSkipped="false" stopOnRisky="false" timeoutForSmallTests="1" timeoutForMediumTests="10" timeoutForLargeTests="60" cacheDirectory=".phpunit.cache" backupStaticProperties="false" requireCoverageMetadata="false">
<testsuites>
<testsuite name="Functional tests">
<directory>tests/</directory>
</testsuite>
</testsuites>
<coverage/>
<php>
<ini name="allow_url_include" value="1"/>
</php>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
23 changes: 19 additions & 4 deletions src/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,34 @@
namespace Kiboko\Component\Flow\JSON;

use Kiboko\Component\Bucket\AcceptanceResultBucket;
use Kiboko\Component\Bucket\RejectionResultBucket;
use Kiboko\Contract\Pipeline\ExtractorInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

readonly class Extractor implements ExtractorInterface

Check failure on line 13 in src/Extractor.php

View workflow job for this annotation

GitHub Actions / phpstan-7

Class Kiboko\Component\Flow\JSON\Extractor implements generic interface Kiboko\Contract\Pipeline\ExtractorInterface but does not specify its types: OutputType

Check failure on line 13 in src/Extractor.php

View workflow job for this annotation

GitHub Actions / phpstan-8

Class Kiboko\Component\Flow\JSON\Extractor implements generic interface Kiboko\Contract\Pipeline\ExtractorInterface but does not specify its types: OutputType

Check failure on line 13 in src/Extractor.php

View workflow job for this annotation

GitHub Actions / phpstan-7

Class Kiboko\Component\Flow\JSON\Extractor implements generic interface Kiboko\Contract\Pipeline\ExtractorInterface but does not specify its types: OutputType
{
public function __construct(
private \SplFileObject $file
) {
}
private \SplFileObject $file,
private LoggerInterface $logger = new NullLogger(),
) {}

public function extract(): iterable
{
$data = null;
while (!$this->file->eof()) {
yield new AcceptanceResultBucket(json_decode($this->file->fgets(), true, 512, \JSON_ERROR_NONE));
try {
$data = json_decode($this->file->fgets(), true, 512, \JSON_ERROR_NONE);

Check warning on line 25 in src/Extractor.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ $data = null; while (!$this->file->eof()) { try { - $data = json_decode($this->file->fgets(), true, 512, \JSON_ERROR_NONE); + $data = json_decode($this->file->fgets(), true, 511, \JSON_ERROR_NONE); (yield new AcceptanceResultBucket($data)); } catch (\Throwable $exception) { $this->logger->critical($exception->getMessage(), ['item' => $data, 'exception' => $exception]);

Check warning on line 25 in src/Extractor.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "IncrementInteger": --- Original +++ New @@ @@ $data = null; while (!$this->file->eof()) { try { - $data = json_decode($this->file->fgets(), true, 512, \JSON_ERROR_NONE); + $data = json_decode($this->file->fgets(), true, 513, \JSON_ERROR_NONE); (yield new AcceptanceResultBucket($data)); } catch (\Throwable $exception) { $this->logger->critical($exception->getMessage(), ['item' => $data, 'exception' => $exception]);

Check failure on line 25 in src/Extractor.php

View workflow job for this annotation

GitHub Actions / phpstan-7

Parameter #1 $json of function json_decode expects string, string|false given.

Check failure on line 25 in src/Extractor.php

View workflow job for this annotation

GitHub Actions / phpstan-8

Parameter #1 $json of function json_decode expects string, string|false given.

Check warning on line 25 in src/Extractor.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "DecrementInteger": --- Original +++ New @@ @@ $data = null; while (!$this->file->eof()) { try { - $data = json_decode($this->file->fgets(), true, 512, \JSON_ERROR_NONE); + $data = json_decode($this->file->fgets(), true, 511, \JSON_ERROR_NONE); (yield new AcceptanceResultBucket($data)); } catch (\Throwable $exception) { $this->logger->critical($exception->getMessage(), ['item' => $data, 'exception' => $exception]);

Check warning on line 25 in src/Extractor.php

View workflow job for this annotation

GitHub Actions / infection

Escaped Mutant for Mutator "IncrementInteger": --- Original +++ New @@ @@ $data = null; while (!$this->file->eof()) { try { - $data = json_decode($this->file->fgets(), true, 512, \JSON_ERROR_NONE); + $data = json_decode($this->file->fgets(), true, 513, \JSON_ERROR_NONE); (yield new AcceptanceResultBucket($data)); } catch (\Throwable $exception) { $this->logger->critical($exception->getMessage(), ['item' => $data, 'exception' => $exception]);

Check failure on line 25 in src/Extractor.php

View workflow job for this annotation

GitHub Actions / phpstan-7

Parameter #1 $json of function json_decode expects string, string|false given.

yield new AcceptanceResultBucket($data);
} catch (\Throwable $exception) {
$this->logger->critical($exception->getMessage(), ['item' => $data, 'exception' => $exception]);
yield new RejectionResultBucket(
'It seems that something failed when decoding the json file.',
$exception,
$data
);
}
}
}
}
32 changes: 20 additions & 12 deletions src/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,35 @@

use Kiboko\Component\Bucket\AcceptanceResultBucket;
use Kiboko\Component\Bucket\EmptyResultBucket;
use Kiboko\Component\Bucket\RejectionResultBucket;
use Kiboko\Contract\Pipeline\LoaderInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

class Loader implements LoaderInterface
readonly class Loader implements LoaderInterface

Check failure on line 14 in src/Loader.php

View workflow job for this annotation

GitHub Actions / phpstan-7

Class Kiboko\Component\Flow\JSON\Loader implements generic interface Kiboko\Contract\Pipeline\LoaderInterface but does not specify its types: InputType, OutputType

Check failure on line 14 in src/Loader.php

View workflow job for this annotation

GitHub Actions / phpstan-8

Class Kiboko\Component\Flow\JSON\Loader implements generic interface Kiboko\Contract\Pipeline\LoaderInterface but does not specify its types: InputType, OutputType

Check failure on line 14 in src/Loader.php

View workflow job for this annotation

GitHub Actions / phpstan-7

Class Kiboko\Component\Flow\JSON\Loader implements generic interface Kiboko\Contract\Pipeline\LoaderInterface but does not specify its types: InputType, OutputType
{
public function __construct(
private readonly \SplFileObject $file,
) {
}
private \SplFileObject $file,
private LoggerInterface $logger = new NullLogger(),
) {}

public function load(): \Generator
{
$line = yield;
$line = yield new EmptyResultBucket();

while (true) {
if ($line === null) {
$line = yield new EmptyResultBucket();
continue;
}
$this->file->fwrite(json_encode($line, \JSON_THROW_ON_ERROR)."\n");
while ($line) {
try {
$this->file->fwrite(json_encode($line, \JSON_THROW_ON_ERROR)."\n");

$line = yield new AcceptanceResultBucket($line);
$line = yield new AcceptanceResultBucket($line);
} catch (\Throwable $exception) {
$this->logger->critical($exception->getMessage(), ['item' => $line, 'exception' => $exception]);
$line = yield new RejectionResultBucket(
'It seems that something went wrong when writing to the json file',
$exception,
$line
);
}
}
}
}
12 changes: 4 additions & 8 deletions tests/functional/PipelineRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,17 @@
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;

final class PipelineRunner implements PipelineRunnerInterface
{
public function run(
\Iterator $source,
\Generator $async,
RejectionInterface $rejection,
StateInterface $state,
StepRejectionInterface $rejection,
StepStateInterface $state,
): \Iterator {
$state->initialize();
$rejection->initialize();

$source->rewind();
$async->rewind();

Expand All @@ -40,8 +39,5 @@ public function run(

$source->next();
}

$rejection->teardown();
$state->teardown();
}
}

0 comments on commit 9bf4a09

Please sign in to comment.