Skip to content

Commit d7f5c5b

Browse files
committed
build: apply linters
1 parent bbfbf19 commit d7f5c5b

File tree

7 files changed

+44
-214
lines changed

7 files changed

+44
-214
lines changed

config/rabbitmq.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99

1010
'driver' => 'rabbitmq',
1111

12-
/*
13-
* Set to "horizon" if you wish to use Laravel Horizon.
14-
*/
1512
'worker' => env('RABBITMQ_WORKER', 'default'),
1613

1714
'dsn' => env('RABBITMQ_DSN', null),

src/Horizon/Listeners/RabbitMQFailedEvent.php

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/Horizon/RabbitMQQueue.php

Lines changed: 0 additions & 115 deletions
This file was deleted.

src/LaravelQueueRabbitMQServiceProvider.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace VladimirYuldashev\LaravelQueueRabbitMQ;
44

@@ -15,9 +15,7 @@ class LaravelQueueRabbitMQServiceProvider extends ServiceProvider
1515
*/
1616
public function register(): void
1717
{
18-
$this->mergeConfigFrom(
19-
__DIR__.'/../config/rabbitmq.php', 'queue.connections.rabbitmq'
20-
);
18+
$this->mergeConfigFrom(__DIR__ . '/../config/rabbitmq.php', 'queue.connections.rabbitmq');
2119
}
2220

2321
/**
@@ -30,7 +28,7 @@ public function boot(): void
3028
/** @var QueueManager $queue */
3129
$queue = $this->app['queue'];
3230

33-
$queue->addConnector('rabbitmq', function () {
31+
$queue->addConnector('rabbitmq', function (): RabbitMQConnector {
3432
return new RabbitMQConnector($this->app['events']);
3533
});
3634
}

src/Queue/Connectors/RabbitMQConnector.php

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,25 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace VladimirYuldashev\LaravelQueueRabbitMQ\Queue\Connectors;
44

5-
use Illuminate\Support\Arr;
6-
use Interop\Amqp\AmqpContext;
7-
use InvalidArgumentException;
8-
use Illuminate\Contracts\Queue\Queue;
9-
use Illuminate\Queue\Events\JobFailed;
10-
use Interop\Amqp\AmqpConnectionFactory;
5+
use Enqueue\AmqpLib\AmqpConnectionFactory as EnqueueAmqpConnectionFactory;
116
use Enqueue\AmqpTools\DelayStrategyAware;
12-
use Illuminate\Contracts\Events\Dispatcher;
13-
use Illuminate\Queue\Events\WorkerStopping;
147
use Enqueue\AmqpTools\RabbitMqDlxDelayStrategy;
8+
use Illuminate\Contracts\Events\Dispatcher;
9+
use Illuminate\Contracts\Queue\Queue;
1510
use Illuminate\Queue\Connectors\ConnectorInterface;
16-
use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\RabbitMQQueue;
11+
use Illuminate\Queue\Events\WorkerStopping;
12+
use Illuminate\Support\Arr;
13+
use Interop\Amqp\AmqpConnectionFactory;
1714
use Interop\Amqp\AmqpConnectionFactory as InteropAmqpConnectionFactory;
18-
use Enqueue\AmqpLib\AmqpConnectionFactory as EnqueueAmqpConnectionFactory;
19-
use VladimirYuldashev\LaravelQueueRabbitMQ\Horizon\Listeners\RabbitMQFailedEvent;
20-
use VladimirYuldashev\LaravelQueueRabbitMQ\Horizon\RabbitMQQueue as HorizonRabbitMQQueue;
15+
use Interop\Amqp\AmqpContext;
16+
use InvalidArgumentException;
17+
use LogicException;
18+
use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\RabbitMQQueue;
2119

2220
class RabbitMQConnector implements ConnectorInterface
2321
{
24-
private const WORKER_DEFAULT='default';
25-
private const WORKER_HORIZON='horizon';
22+
private const WORKER_DEFAULT = 'default';
2623

2724
/**
2825
* @var Dispatcher
@@ -39,15 +36,16 @@ public function __construct(Dispatcher $dispatcher)
3936
*
4037
* @param array $config
4138
*
39+
* @throws LogicException
40+
*
4241
* @return Queue
43-
* @throws \ReflectionException
4442
*/
4543
public function connect(array $config): Queue
4644
{
4745
$factoryClass = Arr::get($config, 'factory_class', EnqueueAmqpConnectionFactory::class);
4846

49-
if (! class_exists($factoryClass) || ! (new \ReflectionClass($factoryClass))->implementsInterface(InteropAmqpConnectionFactory::class)) {
50-
throw new \LogicException(sprintf('The factory_class option has to be valid class that implements "%s"', InteropAmqpConnectionFactory::class));
47+
if (!class_exists($factoryClass) || !(new \ReflectionClass($factoryClass))->implementsInterface(InteropAmqpConnectionFactory::class)) {
48+
throw new LogicException(sprintf('The factory_class option has to be valid class that implements "%s"', InteropAmqpConnectionFactory::class));
5149
}
5250

5351
/** @var AmqpConnectionFactory $factory */
@@ -83,12 +81,6 @@ public function connect(array $config): Queue
8381
return new RabbitMQQueue($context, $config);
8482
}
8583

86-
if ($worker === self::WORKER_HORIZON) {
87-
$this->dispatcher->listen(JobFailed::class, RabbitMQFailedEvent::class);
88-
89-
return new HorizonRabbitMQQueue($context, $config);
90-
}
91-
9284
if (class_exists($worker)) {
9385
return new $worker($context, $config);
9486
}

src/Queue/Jobs/RabbitMQJob.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
namespace VladimirYuldashev\LaravelQueueRabbitMQ\Queue\Jobs;
44

55
use Exception;
6-
use Illuminate\Support\Str;
7-
use Interop\Amqp\AmqpMessage;
8-
use Illuminate\Queue\Jobs\Job;
9-
use Interop\Amqp\AmqpConsumer;
10-
use Illuminate\Queue\Jobs\JobName;
116
use Illuminate\Container\Container;
12-
use Illuminate\Database\DetectsConcurrencyErrors;
137
use Illuminate\Contracts\Queue\Job as JobContract;
8+
use Illuminate\Database\DetectsConcurrencyErrors;
9+
use Illuminate\Queue\Jobs\Job;
10+
use Illuminate\Queue\Jobs\JobName;
11+
use Illuminate\Support\Str;
12+
use Interop\Amqp\AmqpConsumer;
13+
use Interop\Amqp\AmqpMessage;
1414
use VladimirYuldashev\LaravelQueueRabbitMQ\Queue\RabbitMQQueue;
15-
use VladimirYuldashev\LaravelQueueRabbitMQ\Horizon\RabbitMQQueue as HorizonRabbitMQQueue;
1615

1716
class RabbitMQJob extends Job implements JobContract
1817
{
@@ -23,8 +22,13 @@ class RabbitMQJob extends Job implements JobContract
2322
*/
2423
public const ATTEMPT_COUNT_HEADERS_KEY = 'attempts_count';
2524

25+
/** @var RabbitMQQueue */
2626
protected $connection;
27+
28+
/** @var AmqpConsumer */
2729
protected $consumer;
30+
31+
/** @var AmqpMessage */
2832
protected $message;
2933

3034
public function __construct(
@@ -100,11 +104,6 @@ public function delete(): void
100104
parent::delete();
101105

102106
$this->consumer->acknowledge($this->message);
103-
104-
// required for Laravel Horizon
105-
if ($this->connection instanceof HorizonRabbitMQQueue) {
106-
$this->connection->deleteReserved($this->queue, $this);
107-
}
108107
}
109108

110109
/** {@inheritdoc}
@@ -140,7 +139,7 @@ public function release($delay = 0): void
140139
*/
141140
public function getJobId(): string
142141
{
143-
return $this->message->getCorrelationId();
142+
return (string) $this->message->getCorrelationId();
144143
}
145144

146145
/**
@@ -150,7 +149,7 @@ public function getJobId(): string
150149
*
151150
* @return void
152151
*/
153-
public function setJobId($id): void
152+
public function setJobId(string $id): void
154153
{
155154
$this->connection->setCorrelationId($id);
156155
}

src/Queue/RabbitMQQueue.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@
2121

2222
class RabbitMQQueue extends Queue implements QueueContract
2323
{
24-
private const SLEEP_ON_ERROR=5;
24+
private const SLEEP_ON_ERROR = 5;
25+
26+
/** @var int */
2527
protected $sleepOnError;
2628

29+
/** @var string */
2730
protected $queueName;
31+
2832
protected $queueOptions;
29-
protected $exchangeOptions;
3033

34+
protected $exchangeOptions;
3135

3236
/**
3337
* Alternative exchange options to use by producer.
@@ -37,6 +41,7 @@ class RabbitMQQueue extends Queue implements QueueContract
3741
protected $altExchangeOptions;
3842

3943
protected $declaredExchanges = [];
44+
4045
protected $declaredQueues = [];
4146

4247
/**
@@ -161,9 +166,9 @@ public function later($delay, $job, $data = '', $queue = null): ?string
161166
/**
162167
* Release a reserved job back onto the queue.
163168
*
164-
* @param \DateTimeInterface|\DateInterval|int $delay
165-
* @param string|object $job
166-
* @param mixed $data
169+
* @param \DateTimeInterface|\DateInterval|int $delay
170+
* @param string|object $job
171+
* @param mixed $data
167172
* @param string $queue
168173
* @param int $attempts
169174
*
@@ -376,11 +381,11 @@ protected function reportConnectionError(string $action, Throwable $e): void
376381
/** @var LoggerInterface $logger */
377382
$logger = $this->container['log'];
378383

379-
$logger->error('AMQP error while attempting '.$action.': '.$e->getMessage());
384+
$logger->error("AMQP error while attempting {$action}: {$e->getMessage()}");
380385

381386
// If it's set to false, throw an error rather than waiting
382387
if ($this->sleepOnError === false) {
383-
throw new RuntimeException('Error writing data to the connection with RabbitMQ', null, $e);
388+
throw new RuntimeException('Error writing data to the connection with RabbitMQ', 0, $e);
384389
}
385390

386391
// Sleep so that we don't flood the log file

0 commit comments

Comments
 (0)