From c7c37a2caa0293dd56aef4dd23e3b6ef7d38ef95 Mon Sep 17 00:00:00 2001 From: iamfarhad Date: Sun, 8 Jan 2023 23:18:06 +0330 Subject: [PATCH] fix style --- .github/workflows/tests.yml | 4 +-- phpcs.xml | 6 ++--- src/Connectors/RabbitMQConnector.php | 7 +++-- src/Console/ConsumeCommand.php | 7 +++-- src/Consumer.php | 23 +++++++--------- src/Jobs/RabbitMQJob.php | 33 +++++++++-------------- src/LaravelRabbitQueueServiceProvider.php | 7 +++-- src/RabbitQueue.php | 2 +- 8 files changed, 37 insertions(+), 52 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 67a545d..e040c89 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,9 +10,9 @@ jobs: run: runs-on: 'ubuntu-latest' strategy: - fail-fast: true + fail-fast: false matrix: - php: ['8.1'] + php: ['8.1', '8.2'] stability: [prefer-stable] services: diff --git a/phpcs.xml b/phpcs.xml index b637015..230d928 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -1,14 +1,14 @@ The coding standard for our project. - src - + src + tests + - diff --git a/src/Connectors/RabbitMQConnector.php b/src/Connectors/RabbitMQConnector.php index a1de7b6..1f19343 100644 --- a/src/Connectors/RabbitMQConnector.php +++ b/src/Connectors/RabbitMQConnector.php @@ -14,8 +14,7 @@ class RabbitMQConnector implements ConnectorInterface { public function __construct(private readonly Dispatcher $dispatcher) { - }//end __construct() - + } public function connect(array $config = []): Queue { @@ -48,5 +47,5 @@ public function connect(array $config = []): Queue $this->dispatcher->listen(WorkerStopping::class, fn() => $rabbitQueue->close()); return $rabbitQueue; - }//end connect() -}//end class + } +} diff --git a/src/Console/ConsumeCommand.php b/src/Console/ConsumeCommand.php index 488f150..2d95c57 100644 --- a/src/Console/ConsumeCommand.php +++ b/src/Console/ConsumeCommand.php @@ -50,8 +50,7 @@ public function handle(): void $consumer->setPrefetchCount((int) $this->option('prefetch-count')); parent::handle(); - }//end handle() - + } private function consumerTag(): string { @@ -69,5 +68,5 @@ private function consumerTag(): string ); return Str::substr($consumerTag, 0, 255); - }//end consumerTag() -}//end class + } +} diff --git a/src/Consumer.php b/src/Consumer.php index eabba73..48b1a4f 100644 --- a/src/Consumer.php +++ b/src/Consumer.php @@ -32,31 +32,29 @@ class Consumer extends Worker public function setContainer(Container $container): void { $this->container = $container; - }//end setContainer() - + } public function setConsumerTag(string $value): void { $this->consumerTag = $value; - }//end setConsumerTag() - + } public function setMaxPriority(int $value): void { $this->maxPriority = $value; - }//end setMaxPriority() + } public function setPrefetchSize(int $value): void { $this->prefetchSize = $value; - }//end setPrefetchSize() + } public function setPrefetchCount(int $value): void { $this->prefetchCount = $value; - }//end setPrefetchCount() + } /** @@ -175,9 +173,8 @@ function (AMQPMessage $amqpMessage) use ($connection, $workerOptions, $connectio } $this->currentJob = null; - }//end while - }//end daemon() - + } + } /** * Determine if the daemon should process on this iteration. @@ -188,7 +185,7 @@ function (AMQPMessage $amqpMessage) use ($connection, $workerOptions, $connectio protected function daemonShouldRun(WorkerOptions $workerOptions, $connectionName, $queue): bool { return !(($this->isDownForMaintenance)() && ! $workerOptions->force) && !$this->paused; - }//end daemonShouldRun() + } public function stop($status = 0, $options = []): int @@ -198,5 +195,5 @@ public function stop($status = 0, $options = []): int $this->amqpChannel->basic_cancel($this->consumerTag, false, true); return parent::stop($status); - }//end stop() -}//end class + } +} diff --git a/src/Jobs/RabbitMQJob.php b/src/Jobs/RabbitMQJob.php index d7b68c4..a0195a1 100644 --- a/src/Jobs/RabbitMQJob.php +++ b/src/Jobs/RabbitMQJob.php @@ -29,8 +29,7 @@ public function __construct( $this->connectionName = $connectionName; $this->queue = $queue; $this->decoded = $this->payload(); - }//end __construct() - + } /** * {@inheritdoc} @@ -38,8 +37,7 @@ public function __construct( public function getJobId() { return $this->decoded['id'] ?? null; - }//end getJobId() - + } /** * {@inheritdoc} @@ -47,8 +45,7 @@ public function getJobId() public function getRawBody(): string { return $this->amqpMessage->getBody(); - }//end getRawBody() - + } /** * {@inheritdoc} @@ -62,7 +59,7 @@ public function attempts(): int $laravelAttempts = (int) Arr::get($rabbitMQMessageHeaders, 'laravel.attempts', 0); return ($laravelAttempts + 1); - }//end attempts() + } private function convertMessageToFailed(): void @@ -71,8 +68,7 @@ private function convertMessageToFailed(): void $this->rabbitQueue->declareQueue('failed_messages'); $this->rabbitQueue->pushRaw($this->amqpMessage->getBody(), 'failed_messages'); } - }//end convertMessageToFailed() - + } /** * {@inheritdoc} @@ -87,8 +83,7 @@ public function markAsFailed(): void $this->rabbitQueue->reject($this); $this->convertMessageToFailed(); - }//end markAsFailed() - + } /** * {@inheritdoc} @@ -102,8 +97,7 @@ public function delete(): void if (! $this->failed) { $this->rabbitQueue->ack($this); } - }//end delete() - + } /** * Release the job back into the queue. @@ -123,20 +117,17 @@ public function release($delay = 0): void // Because this Job message is always recreated and pushed as new message, this Job message is correctly handled. // We must tell rabbitMQ this job message can be removed by acknowledging the message. $this->rabbitQueue->ack($this); - }//end release() - + } public function getRabbitMQ(): RabbitQueue { return $this->rabbitQueue; - }//end getRabbitMQ() - + } public function getRabbitMQMessage(): AMQPMessage { return $this->amqpMessage; - }//end getRabbitMQMessage() - + } private function getRabbitMQMessageHeaders(): ?array { @@ -148,5 +139,5 @@ private function getRabbitMQMessageHeaders(): ?array } return $headers->getNativeData(); - }//end getRabbitMQMessageHeaders() -}//end class + } +} diff --git a/src/LaravelRabbitQueueServiceProvider.php b/src/LaravelRabbitQueueServiceProvider.php index dcc38c2..e3a78af 100644 --- a/src/LaravelRabbitQueueServiceProvider.php +++ b/src/LaravelRabbitQueueServiceProvider.php @@ -46,8 +46,7 @@ function (): \iamfarhad\LaravelRabbitMQ\Consumer { ] ); }//end if - }//end register() - + } public function boot(): void { @@ -57,5 +56,5 @@ public function boot(): void $queue = $this->app['queue']; $queue->addConnector('rabbitmq', fn(): \iamfarhad\LaravelRabbitMQ\Connectors\RabbitMQConnector => new RabbitMQConnector($this->app['events'])); - }//end boot() -}//end class + } +} diff --git a/src/RabbitQueue.php b/src/RabbitQueue.php index eaf5481..b8ce766 100644 --- a/src/RabbitQueue.php +++ b/src/RabbitQueue.php @@ -136,7 +136,7 @@ public function pop($queue = null) ); } } catch (AMQPProtocolChannelException $amqpProtocolChannelException) { - // If there is not exchange or queue AMQP will throw exception with code 404 + // If there is no exchange or queue AMQP will throw exception with code 404 // We need to catch it and return null if ($amqpProtocolChannelException->amqp_reply_code === 404) { // Because of the channel exception the channel was closed and removed.