Skip to content

Commit 343b06d

Browse files
iamfarhadgithub-actions[bot]
authored andcommitted
Fix styling
1 parent 0f5a950 commit 343b06d

14 files changed

+69
-75
lines changed

.php-cs-fixer.cache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"php":"8.3.19","version":"3.74.0","indent":" ","lineEnding":"\n","rules":{"blank_line_after_namespace":true,"braces_position":true,"class_definition":true,"constant_case":true,"control_structure_braces":true,"control_structure_continuation_position":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline","keep_multiple_spaces_after_comma":true},"no_break_comment":true,"no_closing_tag":true,"no_multiple_statements_per_line":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"single_space_around_construct":{"constructs_followed_by_a_single_space":["abstract","as","case","catch","class","do","else","elseif","final","for","foreach","function","if","interface","namespace","private","protected","public","static","switch","trait","try","use_lambda","while"],"constructs_preceded_by_a_single_space":["as","else","elseif","use_lambda"]},"spaces_inside_parentheses":true,"statement_indentation":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":{"elements":["method","property"]},"encoding":true,"full_opening_tag":true,"array_syntax":{"syntax":"short"},"ordered_imports":{"sort_algorithm":"alpha"},"no_unused_imports":true,"not_operator_with_successor_space":true,"trailing_comma_in_multiline":true,"phpdoc_scalar":true,"unary_operator_spaces":true,"binary_operator_spaces":true,"blank_line_before_statement":{"statements":["break","continue","declare","return","throw","try"]},"phpdoc_single_line_var_spacing":true,"phpdoc_var_without_name":true,"class_attributes_separation":{"elements":{"method":"one"}},"single_trait_insert_per_statement":true},"hashes":{"src\/Jobs\/RabbitMQJob.php":"c3afbc43c2505f068ba7d2d64ba4291b","src\/LaravelRabbitQueueServiceProvider.php":"5652444609c18a3ccdaeba6985b6e7b9","src\/Console\/ConsumeCommand.php":"cbc6b4ed6361a6a39f6519c799d729c0","src\/Consumer.php":"0d22cd50a408fb150b1e44b21291e36d","src\/RabbitQueue.php":"946b594c375156d0494d439aae4f4aa9","src\/Connectors\/RabbitMQConnector.php":"88258e9a1e9e67186d5d2fcae2909a16","tests\/Unit\/Jobs\/RabbitMQJobTest.php":"d437204178ea222b5b30ce3cf0e68122","tests\/Unit\/Connectors\/RabbitMQConnectorTest.php":"85a890942d7d01fb7fb2aca1a37eb2b1","tests\/FeatureTestCase.php":"afb73259bdd41338106efaa175bc7270","tests\/Mocks\/TestJobMock.php":"3fe41f6a18136dee6b6290f310d078dc","tests\/UnitTestCase.php":"136c46197b8084cecd8ff16f3b3dcb46","tests\/Feature\/RabbitMQQueueTest.php":"d6bbfbf1e11350fba94a5552136adb83","tests\/Feature\/Connector\/RabbitMQConnectorTest.php":"21de35c448fd6b7936207acd527b1bd4"}}

src/Connectors/RabbitMQConnector.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
namespace iamfarhad\LaravelRabbitMQ\Connectors;
44

5-
use Illuminate\Queue\Connectors\ConnectorInterface;
6-
use PhpAmqpLib\Connection\AMQPConnectionFactory;
7-
use PhpAmqpLib\Connection\AMQPConnectionConfig;
8-
use Illuminate\Contracts\Events\Dispatcher;
9-
use Illuminate\Queue\Events\WorkerStopping;
105
use iamfarhad\LaravelRabbitMQ\RabbitQueue;
6+
use Illuminate\Contracts\Events\Dispatcher;
117
use Illuminate\Contracts\Queue\Queue;
8+
use Illuminate\Queue\Connectors\ConnectorInterface;
9+
use Illuminate\Queue\Events\WorkerStopping;
10+
use PhpAmqpLib\Connection\AMQPConnectionConfig;
11+
use PhpAmqpLib\Connection\AMQPConnectionFactory;
1212

1313
readonly class RabbitMQConnector implements ConnectorInterface
1414
{
@@ -39,12 +39,12 @@ public function connect(array $config = []): Queue
3939
$amqpConnectionConfig->setSslPassPhrase(config('queue.connections.rabbitmq.options.ssl_options.passphrase'));
4040

4141
// Create AMQP Connection
42-
$connection = AMQPConnectionFactory::create($amqpConnectionConfig);
42+
$connection = AMQPConnectionFactory::create($amqpConnectionConfig);
4343
$defaultQueue = config('queue.connections.rabbitmq.queue');
4444

4545
$rabbitQueue = new RabbitQueue($connection, $defaultQueue);
4646

47-
$this->dispatcher->listen(WorkerStopping::class, fn() => $rabbitQueue->close());
47+
$this->dispatcher->listen(WorkerStopping::class, fn () => $rabbitQueue->close());
4848

4949
return $rabbitQueue;
5050
}

src/Console/ConsumeCommand.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
namespace iamfarhad\LaravelRabbitMQ\Console;
66

7-
use Symfony\Component\Console\Attribute\AsCommand;
87
use Illuminate\Queue\Console\WorkCommand;
98
use Illuminate\Support\Str;
109
use RuntimeException;
10+
use Symfony\Component\Console\Attribute\AsCommand;
1111

1212
#[AsCommand(name: 'rabbitmq:consume')]
1313
final class ConsumeCommand extends WorkCommand
@@ -56,6 +56,7 @@ public function handle(): int
5656

5757
if ($numProcesses < 1) {
5858
$this->error('Number of processes must be at least 1');
59+
5960
return 1;
6061
}
6162

@@ -65,8 +66,9 @@ public function handle(): int
6566
}
6667

6768
// Check if pcntl extension is available
68-
if (!extension_loaded('pcntl')) {
69+
if (! extension_loaded('pcntl')) {
6970
$this->error('The pcntl extension is required for parallel processing');
71+
7072
return 1;
7173
}
7274

@@ -77,6 +79,7 @@ public function handle(): int
7779

7880
if ($pid === -1) {
7981
$this->error("Failed to fork process $i");
82+
8083
continue;
8184
}
8285

@@ -126,7 +129,7 @@ private function consume(): int
126129
try {
127130
$consumer = $this->worker;
128131

129-
if (!$consumer) {
132+
if (! $consumer) {
130133
throw new RuntimeException('Worker instance not initialized');
131134
}
132135

@@ -147,6 +150,7 @@ private function consume(): int
147150
return parent::handle() ?? 0;
148151
} catch (\Throwable $e) {
149152
$this->error($e->getMessage());
153+
150154
return 1;
151155
}
152156
}

src/Consumer.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use PhpAmqpLib\Exception\AMQPRuntimeException;
1111
use PhpAmqpLib\Message\AMQPMessage;
1212
use Throwable;
13-
use iamfarhad\LaravelRabbitMQ\RabbitQueue;
1413

1514
class Consumer extends Worker
1615
{
@@ -28,7 +27,6 @@ class Consumer extends Worker
2827

2928
private object|null $currentJob = null;
3029

31-
3230
public function setContainer(Container $container): void
3331
{
3432
$this->container = $container;
@@ -44,19 +42,16 @@ public function setMaxPriority(int $value): void
4442
$this->maxPriority = $value;
4543
}
4644

47-
4845
public function setPrefetchSize(int $value): void
4946
{
5047
$this->prefetchSize = $value;
5148
}
5249

53-
5450
public function setPrefetchCount(int $value): void
5551
{
5652
$this->prefetchCount = $value;
5753
}
5854

59-
6055
/**
6156
* Listen to the given queue in a loop.
6257
*
@@ -72,7 +67,7 @@ public function daemon($connectionName, $queue, WorkerOptions $options)
7267
}
7368

7469
$timestampOfLastQueueRestart = $this->getTimestampOfLastQueueRestart();
75-
$startTime = (hrtime(true) / 1e9);
70+
$startTime = (hrtime(true) / 1e9);
7671
$jobsProcessed = 0;
7772

7873
$connection = $this->manager->connection($connectionName);
@@ -86,7 +81,7 @@ public function daemon($connectionName, $queue, WorkerOptions $options)
8681
null
8782
);
8883

89-
$jobClass = $connection->getJobClass();
84+
$jobClass = $connection->getJobClass();
9085
$arguments = [];
9186
if ($this->maxPriority !== 0) {
9287
$arguments['priority'] = [
@@ -184,10 +179,9 @@ function (AMQPMessage $amqpMessage) use ($connection, $options, $connectionName,
184179
*/
185180
protected function daemonShouldRun(WorkerOptions $options, $connectionName, $queue): bool
186181
{
187-
return !(($this->isDownForMaintenance)() && ! $options->force) && !$this->paused;
182+
return ! (($this->isDownForMaintenance)() && ! $options->force) && ! $this->paused;
188183
}
189184

190-
191185
public function stop($status = 0, $options = []): int
192186
{
193187
// Tell the server you are going to stop consuming.

src/Jobs/RabbitMQJob.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,29 @@
22

33
namespace iamfarhad\LaravelRabbitMQ\Jobs;
44

5-
use Illuminate\Contracts\Queue\Job as JobContract;
65
use iamfarhad\LaravelRabbitMQ\RabbitQueue;
76
use Illuminate\Container\Container;
8-
use PhpAmqpLib\Message\AMQPMessage;
7+
use Illuminate\Contracts\Queue\Job as JobContract;
98
use Illuminate\Queue\Jobs\Job;
109
use Illuminate\Support\Arr;
1110
use JsonException;
11+
use PhpAmqpLib\Message\AMQPMessage;
1212

1313
final class RabbitMQJob extends Job implements JobContract
1414
{
1515
private readonly array $decoded;
1616

17-
1817
public function __construct(
1918
Container $container,
2019
protected RabbitQueue $rabbitQueue,
2120
protected AMQPMessage $amqpMessage,
2221
string $connectionName,
2322
string $queue
2423
) {
25-
$this->container = $container;
24+
$this->container = $container;
2625
$this->connectionName = $connectionName;
27-
$this->queue = $queue;
28-
$this->decoded = $this->payload();
26+
$this->queue = $queue;
27+
$this->decoded = $this->payload();
2928
}
3029

3130
/**
@@ -58,7 +57,6 @@ public function attempts(): int
5857
return ($laravelAttempts + 1);
5958
}
6059

61-
6260
/**
6361
* @throws JsonException
6462
*/

src/LaravelRabbitQueueServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use iamfarhad\LaravelRabbitMQ\Connectors\RabbitMQConnector;
66
use iamfarhad\LaravelRabbitMQ\Console\ConsumeCommand;
7-
use iamfarhad\LaravelRabbitMQ\Consumer; // Added missing import
7+
// Added missing import
88
use Illuminate\Contracts\Debug\ExceptionHandler;
99
use Illuminate\Support\ServiceProvider;
1010

@@ -19,7 +19,7 @@ public function register(): void
1919

2020
if ($this->app->runningInConsole()) {
2121
$this->app->singleton('rabbitmq.consumer', function ($app): Consumer {
22-
$isDownForMaintenance = fn(): bool => $app->isDownForMaintenance();
22+
$isDownForMaintenance = fn (): bool => $app->isDownForMaintenance();
2323

2424
return new Consumer(
2525
$app['queue'],

0 commit comments

Comments
 (0)