From bcb326969898c1d4371f3ce699bfb43321bb51f5 Mon Sep 17 00:00:00 2001 From: sebprt Date: Wed, 22 Nov 2023 11:38:44 +0100 Subject: [PATCH 1/6] Fixed phpstan errors --- src/Extractor.php | 4 ++-- src/Loader.php | 13 +++++++------ src/Rejection.php | 12 ++++++------ src/State.php | 4 +--- src/StateManager.php | 2 +- 5 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/Extractor.php b/src/Extractor.php index d45cfe5..1fa7939 100644 --- a/src/Extractor.php +++ b/src/Extractor.php @@ -32,7 +32,7 @@ public static function withoutAuthentication( string $host, string $vhost, string $topic, - ?int $port = null, + int $port = null, ): self { $connection = new Client([ 'host' => $host, @@ -52,7 +52,7 @@ public static function withAuthentication( string $topic, ?string $user, ?string $password, - ?int $port = null, + int $port = null, ): self { $connection = new Client([ 'host' => $host, diff --git a/src/Loader.php b/src/Loader.php index 0656f14..812d78e 100644 --- a/src/Loader.php +++ b/src/Loader.php @@ -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 @@ -33,8 +34,8 @@ public static function withoutAuthentication( string $host, string $vhost, string $topic, - ?string $exchange = null, - ?int $port = null, + string $exchange = null, + int $port = null, ): self { $connection = new Client([ 'host' => $host, @@ -54,8 +55,8 @@ public static function withAuthentication( string $topic, ?string $user, ?string $password, - ?string $exchange = null, - ?int $port = null, + string $exchange = null, + int $port = null, ): self { $connection = new Client([ 'host' => $host, @@ -71,9 +72,9 @@ public static function withAuthentication( public function load(): \Generator { - $line = yield; + $line = new EmptyResultBucket(); - while (true) { + while ($line) { $this->channel->publish( json_encode($line, \JSON_THROW_ON_ERROR), [ diff --git a/src/Rejection.php b/src/Rejection.php index 418522d..62a3979 100644 --- a/src/Rejection.php +++ b/src/Rejection.php @@ -34,8 +34,8 @@ public static function withoutAuthentication( string $host, string $vhost, string $topic, - ?string $exchange = null, - ?int $port = null, + string $exchange = null, + int $port = null, ): self { $connection = new Client([ 'host' => $host, @@ -56,8 +56,8 @@ public static function withAuthentication( string $topic, ?string $user, ?string $password, - ?string $exchange = null, - ?int $port = null, + string $exchange = null, + int $port = null, ): self { $connection = new Client([ 'host' => $host, @@ -71,7 +71,7 @@ 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([ @@ -87,7 +87,7 @@ 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([ diff --git a/src/State.php b/src/State.php index a4f3a75..fca8097 100644 --- a/src/State.php +++ b/src/State.php @@ -4,7 +4,6 @@ namespace Kiboko\Component\Flow\RabbitMQ; -use Kiboko\Contract\Pipeline\StepCodeInterface; use Kiboko\Contract\Pipeline\StepStateInterface; final class State implements StepStateInterface @@ -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 { diff --git a/src/StateManager.php b/src/StateManager.php index 3c0a86a..c8daa6d 100644 --- a/src/StateManager.php +++ b/src/StateManager.php @@ -73,7 +73,7 @@ private function sendUpdate(): void $this->channel->publish( 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), ], \JSON_THROW_ON_ERROR), From 60e89756e97c3f1384cb401af7b7428536180117 Mon Sep 17 00:00:00 2001 From: sebprt Date: Wed, 22 Nov 2023 14:50:16 +0100 Subject: [PATCH 2/6] Added rule to ignore while(true) statement --- src/Loader.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Loader.php b/src/Loader.php index 812d78e..96ad506 100644 --- a/src/Loader.php +++ b/src/Loader.php @@ -74,7 +74,8 @@ public function load(): \Generator { $line = new EmptyResultBucket(); - while ($line) { + /* @phpstan-ignore-next-line */ + while (true) { $this->channel->publish( json_encode($line, \JSON_THROW_ON_ERROR), [ From eec38083b3c819523ff35ca2f7077c05c24db9f0 Mon Sep 17 00:00:00 2001 From: sebprt Date: Wed, 22 Nov 2023 15:09:10 +0100 Subject: [PATCH 3/6] Updated github actions --- .github/workflows/phpstan-5.yaml | 23 -------------------- .github/workflows/phpstan-6.yaml | 2 +- .github/workflows/phpstan-7.yaml | 2 +- .github/workflows/phpstan-8.yaml | 2 +- .github/workflows/quality.yaml | 36 ++++++++++++++++---------------- 5 files changed, 21 insertions(+), 44 deletions(-) delete mode 100644 .github/workflows/phpstan-5.yaml diff --git a/.github/workflows/phpstan-5.yaml b/.github/workflows/phpstan-5.yaml deleted file mode 100644 index 906b4c9..0000000 --- a/.github/workflows/phpstan-5.yaml +++ /dev/null @@ -1,23 +0,0 @@ -name: PHPStan level 5 -on: push -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: 5 - php_version: '8.2' diff --git a/.github/workflows/phpstan-6.yaml b/.github/workflows/phpstan-6.yaml index 8fe418d..b6bd269 100644 --- a/.github/workflows/phpstan-6.yaml +++ b/.github/workflows/phpstan-6.yaml @@ -1,7 +1,7 @@ name: PHPStan level 6 on: push jobs: - phpstan: + phpstan-6: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/phpstan-7.yaml b/.github/workflows/phpstan-7.yaml index e7d8d6e..4505ba2 100644 --- a/.github/workflows/phpstan-7.yaml +++ b/.github/workflows/phpstan-7.yaml @@ -1,7 +1,7 @@ name: PHPStan level 7 on: push jobs: - phpstan: + phpstan-7: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/phpstan-8.yaml b/.github/workflows/phpstan-8.yaml index 39cebe0..3dbb252 100644 --- a/.github/workflows/phpstan-8.yaml +++ b/.github/workflows/phpstan-8.yaml @@ -1,7 +1,7 @@ name: PHPStan level 8 on: push jobs: - phpstan: + phpstan-8: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/quality.yaml b/.github/workflows/quality.yaml index 8e70ec6..6135a48 100644 --- a/.github/workflows/quality.yaml +++ b/.github/workflows/quality.yaml @@ -1,4 +1,4 @@ -name: Quality (PHPStan lvl 4) +name: Quality (PHPStan lvl 5) on: push jobs: cs-fixer: @@ -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' From 5c222c069500e033c924ce793e9ddad9692b6817 Mon Sep 17 00:00:00 2001 From: sebprt Date: Thu, 23 Nov 2023 15:20:27 +0100 Subject: [PATCH 4/6] Removed php version option --- .github/workflows/quality.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/quality.yaml b/.github/workflows/quality.yaml index 6135a48..a01ebd4 100644 --- a/.github/workflows/quality.yaml +++ b/.github/workflows/quality.yaml @@ -33,4 +33,3 @@ jobs: with: path: src/ level: 5 - php_version: '8.2' From fb0a3ecd85eb4ba25c29a5924de0bbc293ef491d Mon Sep 17 00:00:00 2001 From: sebprt Date: Wed, 29 Nov 2023 16:26:09 +0100 Subject: [PATCH 5/6] Updated php-cs-fixer rules --- .php-cs-fixer.dist.php | 9 +++++++-- src/Extractor.php | 6 +++--- src/Loader.php | 12 ++++++------ src/Rejection.php | 28 ++++++++++++++-------------- src/State.php | 2 +- src/StateManager.php | 6 +++--- 6 files changed, 34 insertions(+), 29 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 218caa4..7002f15 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -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, @@ -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 diff --git a/src/Extractor.php b/src/Extractor.php index 1fa7939..1ef9f08 100644 --- a/src/Extractor.php +++ b/src/Extractor.php @@ -32,7 +32,7 @@ public static function withoutAuthentication( string $host, string $vhost, string $topic, - int $port = null, + ?int $port = null, ): self { $connection = new Client([ 'host' => $host, @@ -52,7 +52,7 @@ public static function withAuthentication( string $topic, ?string $user, ?string $password, - int $port = null, + ?int $port = null, ): self { $connection = new Client([ 'host' => $host, @@ -75,7 +75,7 @@ public function extract(): iterable } $this->channel->ack($message); - 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)); } } } diff --git a/src/Loader.php b/src/Loader.php index 96ad506..b19b6f9 100644 --- a/src/Loader.php +++ b/src/Loader.php @@ -34,8 +34,8 @@ public static function withoutAuthentication( string $host, string $vhost, string $topic, - string $exchange = null, - int $port = null, + ?string $exchange = null, + ?int $port = null, ): self { $connection = new Client([ 'host' => $host, @@ -55,8 +55,8 @@ public static function withAuthentication( string $topic, ?string $user, ?string $password, - string $exchange = null, - int $port = null, + ?string $exchange = null, + ?int $port = null, ): self { $connection = new Client([ 'host' => $host, @@ -74,10 +74,10 @@ public function load(): \Generator { $line = new EmptyResultBucket(); - /* @phpstan-ignore-next-line */ + // @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', ], diff --git a/src/Rejection.php b/src/Rejection.php index 62a3979..7305c59 100644 --- a/src/Rejection.php +++ b/src/Rejection.php @@ -29,13 +29,19 @@ public function __construct( ); } + public function teardown(): void + { + $this->channel->close(); + $this->connection->stop(); + } + public static function withoutAuthentication( string $stepUuid, string $host, string $vhost, string $topic, - string $exchange = null, - int $port = null, + ?string $exchange = null, + ?int $port = null, ): self { $connection = new Client([ 'host' => $host, @@ -56,8 +62,8 @@ public static function withAuthentication( string $topic, ?string $user, ?string $password, - string $exchange = null, - int $port = null, + ?string $exchange = null, + ?int $port = null, ): self { $connection = new Client([ 'host' => $host, @@ -71,10 +77,10 @@ public static function withAuthentication( return new self($connection, stepUuid: $stepUuid, topic: $topic, exchange: $exchange); } - public function reject(StepCodeInterface $step, array|object $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, @@ -87,10 +93,10 @@ public function reject(StepCodeInterface $step, array|object $rejection, \Throwa ); } - public function rejectWithReason(StepCodeInterface $step, array|object $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, @@ -113,10 +119,4 @@ public function initialize(): void autoDelete: true, ); } - - public function teardown(): void - { - $this->channel->close(); - $this->connection->stop(); - } } diff --git a/src/State.php b/src/State.php index fca8097..04103c8 100644 --- a/src/State.php +++ b/src/State.php @@ -44,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()), ]; } diff --git a/src/StateManager.php b/src/StateManager.php index c8daa6d..5d38f43 100644 --- a/src/StateManager.php +++ b/src/StateManager.php @@ -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', From 60f2edeb32951caa1fa730772e9008dcc8a260fa Mon Sep 17 00:00:00 2001 From: sebprt Date: Wed, 20 Dec 2023 09:07:15 +0100 Subject: [PATCH 6/6] Added missing yield --- src/Loader.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Loader.php b/src/Loader.php index b19b6f9..ad7eac1 100644 --- a/src/Loader.php +++ b/src/Loader.php @@ -72,7 +72,7 @@ public static function withAuthentication( public function load(): \Generator { - $line = new EmptyResultBucket(); + $line = yield new EmptyResultBucket(); // @phpstan-ignore-next-line while (true) {