Skip to content

Commit

Permalink
cs fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nekufa committed Jan 17, 2024
1 parent f6752db commit f141c54
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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');
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/Consumer/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
6 changes: 3 additions & 3 deletions src/Message/Msg.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
Expand Down
7 changes: 4 additions & 3 deletions src/NKeys/Base32.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/Functional/StreamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 10 additions & 7 deletions tests/Functional/SubjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@

class SubjectTest extends FunctionalTestCase
{
private bool $tested = false;
private int $responseCounter = 0;
private $socket;

public function testPublishSubscribe()
{
$this->tested = false;
Expand Down Expand Up @@ -91,21 +94,21 @@ 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');
$this->responseCounter++;
});

//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
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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()
Expand Down

0 comments on commit f141c54

Please sign in to comment.