From f141c540c69103de3e30dbb353a4099c8309b9a2 Mon Sep 17 00:00:00 2001 From: dmitry krokhin Date: Wed, 17 Jan 2024 16:54:21 +0300 Subject: [PATCH] cs fixes --- .github/workflows/tests.yml | 2 +- src/Client.php | 13 +++++++------ src/Consumer/Consumer.php | 8 +++++--- src/Message/Msg.php | 6 +++--- src/NKeys/Base32.php | 7 ++++--- tests/Functional/StreamTest.php | 2 +- tests/Functional/SubjectTest.php | 17 ++++++++++------- 7 files changed, 31 insertions(+), 24 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 524caf1..a7cda00 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -8,7 +8,7 @@ jobs: NATS_TEST_LOG: 1 strategy: matrix: - php: ["8.1", "8.2"] + php: ["8.1", "8.2", "8.3"] steps: - uses: actions/checkout@v2 - uses: shivammathur/setup-php@v2 diff --git a/src/Client.php b/src/Client.php index 836bb06..db920f3 100644 --- a/src/Client.php +++ b/src/Client.php @@ -302,6 +302,9 @@ public function process(null|int|float $timeout = 0, bool $reply = true) case Msg::class: $payload = ''; + if (!($message instanceof Msg)) { + continue; + } if ($message->length) { $iteration = 0; while (strlen($payload) < $message->length) { @@ -316,7 +319,9 @@ public function process(null|int|float $timeout = 0, bool $reply = true) continue; } if (strlen($payloadLine) != $message->length) { - $this->logger?->debug('got ' . strlen($payloadLine) . '/' . $message->length . ': ' . $payloadLine); + $this->logger?->debug( + 'got ' . strlen($payloadLine) . '/' . $message->length . ': ' . $payloadLine + ); } $payload .= $payloadLine; } @@ -379,11 +384,7 @@ private function enableTls(bool $requireClientCert): void stream_context_set_option($this->context, 'ssl', 'cafile', $this->configuration->tlsCaFile); } - if (!stream_socket_enable_crypto( - $this->socket, - true, - STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT - )) { + if (!stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_TLSv1_2_CLIENT)) { throw new Exception('Failed to connect: Error enabling TLS'); } } diff --git a/src/Consumer/Consumer.php b/src/Consumer/Consumer.php index 558c605..dc56eb9 100644 --- a/src/Consumer/Consumer.php +++ b/src/Consumer/Consumer.php @@ -26,9 +26,11 @@ public function __construct( public function create($ifNotExists = true): self { if ($this->shouldCreateConsumer($ifNotExists)) { - $command = $this->configuration->isEphemeral() ? - 'CONSUMER.CREATE.' . $this->getStream() : - 'CONSUMER.DURABLE.CREATE.' . $this->getStream() . '.' . $this->getName(); + if ($this->configuration->isEphemeral()) { + $command = 'CONSUMER.CREATE.' . $this->getStream(); + } else { + $command = 'CONSUMER.DURABLE.CREATE.' . $this->getStream() . '.' . $this->getName(); + } $result = $this->client->api($command, $this->configuration->toArray()); diff --git a/src/Message/Msg.php b/src/Message/Msg.php index 2184bb3..a27622e 100644 --- a/src/Message/Msg.php +++ b/src/Message/Msg.php @@ -107,8 +107,8 @@ public function render(): string private static function tryParseMessageTime(array $values): array { - if (!array_key_exists('replyTo', $values) - || !str_starts_with($values['replyTo'], '$JS.ACK') + if ( + !array_key_exists('replyTo', $values) || !str_starts_with($values['replyTo'], '$JS.ACK') ) { # This is not a JetStream message return $values; @@ -129,7 +129,7 @@ private static function tryParseMessageTime(array $values): array return $values; } - $values['timestampNanos'] = (int)$tokens[9]; + $values['timestampNanos'] = (int) $tokens[9]; return $values; } diff --git a/src/NKeys/Base32.php b/src/NKeys/Base32.php index 0dfaf2c..1604c0d 100644 --- a/src/NKeys/Base32.php +++ b/src/NKeys/Base32.php @@ -158,8 +158,9 @@ public function decode(string $input): string } for ($i = 0; $i < 4; $i++) { - if ($paddingCharCount === $allowedValues[$i] && - substr($input, -($allowedValues[$i])) !== str_repeat(self::MAP[32], $allowedValues[$i]) + if ( + $paddingCharCount === $allowedValues[$i] + && substr($input, -($allowedValues[$i])) !== str_repeat(self::MAP[32], $allowedValues[$i]) ) { throw new InvalidArgumentException('Invalid base32 data'); } @@ -227,7 +228,7 @@ private function decodeEightBits(int $bitCount, array $eightBits): string $binaryString = ''; for ($z = 0; $z < $bitCount; $z++) { - $binaryString .= (($y = chr((int)base_convert($eightBits[$z], 2, 10))) || ord($y) === 48) ? $y : ''; + $binaryString .= (($y = chr((int) base_convert($eightBits[$z], 2, 10))) || ord($y) === 48) ? $y : ''; } return $binaryString; diff --git a/tests/Functional/StreamTest.php b/tests/Functional/StreamTest.php index e0250ef..d1c7afe 100644 --- a/tests/Functional/StreamTest.php +++ b/tests/Functional/StreamTest.php @@ -355,7 +355,7 @@ public function testBatching() private function assertWrongNumPending(Consumer $consumer, ?int $expected = null, int $loops = 100): void { for ($i = 1; $i <= $loops; $i++) { - $actual = $consumer->info()->getValue('num_pending'); + $actual = $consumer->info()->getValue('num_pending'); if ($actual === $expected) { break; diff --git a/tests/Functional/SubjectTest.php b/tests/Functional/SubjectTest.php index 6c2fb68..6ce1369 100644 --- a/tests/Functional/SubjectTest.php +++ b/tests/Functional/SubjectTest.php @@ -11,7 +11,10 @@ class SubjectTest extends FunctionalTestCase { + private bool $tested = false; private int $responseCounter = 0; + private $socket; + public function testPublishSubscribe() { $this->tested = false; @@ -91,13 +94,13 @@ public function testRequestReplyToDefault() $client = $this->createClient(); //subscriptions should be empty to begin with - $this->assertEquals(0, sizeof($refSubscriptions->getValue($client))); + $this->assertEquals(0, count($refSubscriptions->getValue($client))); $client->subscribe('hello.request', $this->greet(...)); $this->responseCounter = 0; //Adding one subscription for hello.request - $this->assertEquals(1, sizeof($refSubscriptions->getValue($client))); + $this->assertEquals(1, count($refSubscriptions->getValue($client))); $client->request('hello.request', 'Nekufa1', function ($response) use ($client) { $this->assertEquals($response->body, 'Hello, Nekufa1'); @@ -105,7 +108,7 @@ public function testRequestReplyToDefault() }); //Added second subscription for reply message - $this->assertEquals(2, sizeof($refSubscriptions->getValue($client))); + $this->assertEquals(2, count($refSubscriptions->getValue($client))); $this->assertStringStartsWith('_INBOX.', $refSubscriptions->getValue($client)[1]['name']); // processing requests @@ -118,7 +121,7 @@ public function testRequestReplyToDefault() $this->assertEquals(1, $this->responseCounter); //back down to one subscription when reply is received - $this->assertEquals(1, sizeof($refSubscriptions->getValue($client))); + $this->assertEquals(1, count($refSubscriptions->getValue($client))); } public function testRequestWithCustomReplyTo() @@ -133,14 +136,14 @@ public function testRequestWithCustomReplyTo() $client->subscribe('hello.request', $this->greet(...)); $this->responseCounter = 0; - $this->assertEquals(1, sizeof($property->getValue($client))); + $this->assertEquals(1, count($property->getValue($client))); $client->request('hello.request', 'Nekufa1', function ($response) use ($client) { $this->assertEquals($response->body, 'Hello, Nekufa1'); $this->responseCounter++; }); - $this->assertEquals(2, sizeof($property->getValue($client))); + $this->assertEquals(2, count($property->getValue($client))); $this->assertStringStartsWith('_MY_CUSTOM_PREFIX.', $property->getValue($client)[1]['name']); // processing requests @@ -152,7 +155,7 @@ public function testRequestWithCustomReplyTo() $this->assertEquals(1, $this->responseCounter); - $this->assertEquals(1, sizeof($property->getValue($client))); + $this->assertEquals(1, count($property->getValue($client))); } public function testUnsubscribe()