Skip to content

Commit

Permalink
Merge pull request #12 from php-etl/feature/update-contracts
Browse files Browse the repository at this point in the history
Fixed phpstan errors
  • Loading branch information
gplanchat authored Dec 22, 2023
2 parents 8f938c9 + 60f2ede commit 7491939
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 66 deletions.
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
35 changes: 17 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,19 @@ 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
9 changes: 7 additions & 2 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@
'php_unit_construct' => true,
'no_useless_sprintf' => true,
'no_homoglyph_names' => true,
'native_function_invocation' => true,
'native_constant_invocation' => true,
'native_function_invocation' => [
'include' => ['@all'],
],
'native_constant_invocation' => [
'include' => ['@all'],
],
'modernize_types_casting' => true,
'logical_operators' => true,
'is_null' => true,
Expand All @@ -35,6 +39,7 @@
'ereg_to_preg' => true,
'dir_constant' => true,
'method_chaining_indentation' => false,
'nullable_type_declaration_for_default_null_value' => true
])
->setFinder($finder)
->setCacheFile('.php-cs-fixer.cache') // forward compatibility with 3.x line
Expand Down
2 changes: 1 addition & 1 deletion src/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function extract(): iterable
}
$this->channel->ack($message);

Check failure on line 76 in src/Extractor.php

View workflow job for this annotation

GitHub Actions / phpstan-8

Parameter #1 $message of method Bunny\Channel::ack() expects Bunny\Message, Bunny\Message|React\Promise\PromiseInterface given.

yield new AcceptanceResultBucket(json_decode($message->content, true, 512, \JSON_THROW_ON_ERROR));
yield new AcceptanceResultBucket(\json_decode($message->content, true, 512, \JSON_THROW_ON_ERROR));

Check failure on line 78 in src/Extractor.php

View workflow job for this annotation

GitHub Actions / phpstan-8

Access to an undefined property Bunny\Message|React\Promise\PromiseInterface::$content.
}
}
}
6 changes: 4 additions & 2 deletions src/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Bunny\Channel;
use Bunny\Client;
use Kiboko\Component\Bucket\AcceptanceResultBucket;
use Kiboko\Component\Bucket\EmptyResultBucket;
use Kiboko\Contract\Pipeline\LoaderInterface;

final readonly class Loader implements LoaderInterface

Check failure on line 13 in src/Loader.php

View workflow job for this annotation

GitHub Actions / phpstan-8

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

Check failure on line 13 in src/Loader.php

View workflow job for this annotation

GitHub Actions / phpstan-6

Class Kiboko\Component\Flow\RabbitMQ\Loader implements generic interface Kiboko\Contract\Pipeline\LoaderInterface but does not specify its types: InputType, OutputType
Expand Down Expand Up @@ -71,11 +72,12 @@ public static function withAuthentication(

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

// @phpstan-ignore-next-line
while (true) {
$this->channel->publish(
json_encode($line, \JSON_THROW_ON_ERROR),
\json_encode($line, \JSON_THROW_ON_ERROR),
[
'content-type' => 'application/json',
],
Expand Down
20 changes: 10 additions & 10 deletions src/Rejection.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ public function __construct(
);
}

public function teardown(): void
{
$this->channel->close();
$this->connection->stop();
}

public static function withoutAuthentication(
string $stepUuid,
string $host,
Expand Down Expand Up @@ -71,10 +77,10 @@ public static function withAuthentication(
return new self($connection, stepUuid: $stepUuid, topic: $topic, exchange: $exchange);
}

public function reject(StepCodeInterface $step, object|array $rejection, ?\Throwable $exception = null): void
public function reject(StepCodeInterface $step, array|object $rejection, ?\Throwable $exception = null): void
{
$this->channel->publish(
json_encode([
\json_encode([
'item' => $rejection,
'exception' => $exception,
'step' => $this->stepUuid,
Expand All @@ -87,10 +93,10 @@ public function reject(StepCodeInterface $step, object|array $rejection, ?\Throw
);
}

public function rejectWithReason(StepCodeInterface $step, object|array $rejection, string $reason, ?\Throwable $exception = null): void
public function rejectWithReason(StepCodeInterface $step, array|object $rejection, string $reason, ?\Throwable $exception = null): void
{
$this->channel->publish(
json_encode([
\json_encode([
'item' => $rejection,
'exception' => $exception,
'step' => $this->stepUuid,
Expand All @@ -113,10 +119,4 @@ public function initialize(): void
autoDelete: true,
);
}

public function teardown(): void
{
$this->channel->close();
$this->connection->stop();
}
}
6 changes: 2 additions & 4 deletions src/State.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Kiboko\Component\Flow\RabbitMQ;

use Kiboko\Contract\Pipeline\StepCodeInterface;
use Kiboko\Contract\Pipeline\StepStateInterface;

final class State implements StepStateInterface
Expand All @@ -17,8 +16,7 @@ public function __construct(
private readonly StateManager $manager,
private readonly string $stepCode,
private readonly string $stepLabel,
) {
}
) {}

public function accept(int $count = 1): void
{
Expand Down Expand Up @@ -46,7 +44,7 @@ public function toArray(): array
return [
'code' => $this->stepCode,
'label' => $this->stepLabel ?: $this->stepCode,
'metrics' => iterator_to_array($this->walkMetrics()),
'metrics' => \iterator_to_array($this->walkMetrics()),
];
}

Expand Down
6 changes: 3 additions & 3 deletions src/StateManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ private function sendUpdate(): void
$date = new \DateTimeImmutable();

$this->channel->publish(
json_encode([
\json_encode([
'messageNumber' => ++$this->messageCount,
'id' => \uuid_create(\UUID_TYPE_RANDOM),
'id' => \uuid_create(UUID_TYPE_RANDOM),
'date' => ['date' => $date->format('c'), 'tz' => $date->getTimezone()->getName()],
'stepsUpdates' => array_map(fn (State $step) => $step->toArray(), $this->steps),
'stepsUpdates' => \array_map(fn (State $step) => $step->toArray(), $this->steps),
], \JSON_THROW_ON_ERROR),
[
'content-type' => 'application/json',
Expand Down

0 comments on commit 7491939

Please sign in to comment.