Skip to content

Commit 4edd9c8

Browse files
authored
Merge pull request #24 from palpalani/develop
CS improvements
2 parents 69ea5f4 + b9bf20e commit 4edd9c8

File tree

5 files changed

+18
-39
lines changed

5 files changed

+18
-39
lines changed

pint.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{
22
"preset": "laravel",
33
"rules": {
4-
"@PER": true,
5-
"@PER:risky": true,
4+
"@PER-CS": true,
5+
"@PER-CS:risky": true,
6+
"@PHP82Migration": true,
67
"simplified_null_return": true,
78
"braces": false,
89
"new_with_braces": {

src/Jobs/DispatcherJob.php

+1-7
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ class DispatcherJob implements ShouldQueue
1717

1818
protected bool $plain = false;
1919

20-
public function __construct(protected $data)
21-
{
22-
}
20+
public function __construct(protected $data) {}
2321

2422
/**
2523
* @return mixed
@@ -37,7 +35,6 @@ public function getPayload()
3735
}
3836

3937
/**
40-
* @param bool $plain
4138
* @return $this
4239
*/
4340
public function setPlain(bool $plain = true): self
@@ -47,9 +44,6 @@ public function setPlain(bool $plain = true): self
4744
return $this;
4845
}
4946

50-
/**
51-
* @return bool
52-
*/
5347
public function isPlain(): bool
5448
{
5549
return $this->plain;

src/Sqs/Connector.php

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class Connector extends SqsConnector
1313
/**
1414
* Establish a queue connection.
1515
*
16-
* @param array $config
1716
* @return \Illuminate\Contracts\Queue\Queue
1817
*/
1918
public function connect(array $config)

src/Sqs/Queue.php

+10-25
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class Queue extends SqsQueue
2323
* @param object|string $job
2424
* @param string $queue
2525
* @param mixed $data
26-
* @return string
2726
*
2827
* @throws JsonException
2928
*/
@@ -33,18 +32,14 @@ protected function createPayload($job, $queue = null, $data = ''): string
3332
return parent::createPayload($job, $queue, $data);
3433
}
3534

36-
$handlerJob = $this->getClass($queue).'@handle';
35+
$handlerJob = $this->getClass($queue) . '@handle';
3736

3837
return $job->isPlain() ? \json_encode($job->getPayload(), JSON_THROW_ON_ERROR) : \json_encode([
3938
'job' => $handlerJob,
4039
'data' => $job->getPayload(),
4140
], JSON_THROW_ON_ERROR);
4241
}
4342

44-
/**
45-
* @param $queue
46-
* @return string
47-
*/
4843
private function getClass($queue = null): string
4944
{
5045
if (! $queue) {
@@ -54,7 +49,7 @@ private function getClass($queue = null): string
5449
$queueId = explode('/', $queue);
5550
$queueId = array_pop($queueId);
5651

57-
return (array_key_exists($queueId, Config::get('sqs-queue-reader.handlers')))
52+
return (\array_key_exists($queueId, Config::get('sqs-queue-reader.handlers')))
5853
? Config::get('sqs-queue-reader.handlers')[$queueId]['class']
5954
: Config::get('sqs-queue-reader.default-handler')['class'];
6055
}
@@ -74,7 +69,7 @@ public function pop($queue = null)
7469
$queueId = explode('/', $queue);
7570
$queueId = array_pop($queueId);
7671

77-
$count = (array_key_exists($queueId, Config::get('sqs-queue-reader.handlers')))
72+
$count = (\array_key_exists($queueId, Config::get('sqs-queue-reader.handlers')))
7873
? Config::get('sqs-queue-reader.handlers')[$queueId]['count']
7974
: Config::get('sqs-queue-reader.default-handler')['count'];
8075

@@ -87,7 +82,7 @@ public function pop($queue = null)
8782
]);
8883

8984
if (isset($response['Messages']) && count($response['Messages']) > 0) {
90-
$class = (array_key_exists($queueId, $this->container['config']->get('sqs-queue-reader.handlers')))
85+
$class = (\array_key_exists($queueId, $this->container['config']->get('sqs-queue-reader.handlers')))
9186
? $this->container['config']->get('sqs-queue-reader.handlers')[$queueId]['class']
9287
: $this->container['config']->get('sqs-queue-reader.default-handler')['class'];
9388

@@ -100,20 +95,16 @@ public function pop($queue = null)
10095
return new SqsJob($this->container, $this->sqs, $response, $this->connectionName, $queue);
10196
}
10297
} catch (AwsException $e) {
103-
$msg = 'Line: '.$e->getLine().', '.$e->getFile().', '.$e->getMessage();
98+
$msg = 'Line: ' . $e->getLine() . ', ' . $e->getFile() . ', ' . $e->getMessage();
10499

105-
throw new \RuntimeException('Aws SQS error: '.$msg);
100+
throw new \RuntimeException('Aws SQS error: ' . $msg);
106101
}
107102
}
108103

109104
/**
110-
* @param array|string $payload
111-
* @param string $class
112-
* @return array|string
113-
*
114105
* @throws JsonException
115106
*/
116-
private function modifySinglePayload(array | string $payload, string $class): array | string
107+
private function modifySinglePayload(array|string $payload, string $class): array|string
117108
{
118109
if (! is_array($payload)) {
119110
$payload = \json_decode($payload, true, 512, JSON_THROW_ON_ERROR);
@@ -123,21 +114,17 @@ private function modifySinglePayload(array | string $payload, string $class): ar
123114

124115
$payload['Body'] = \json_encode([
125116
'uuid' => (string) Str::uuid(),
126-
'job' => $class.'@handle',
117+
'job' => $class . '@handle',
127118
'data' => $body['data'] ?? $body,
128119
], JSON_THROW_ON_ERROR);
129120

130121
return $payload;
131122
}
132123

133124
/**
134-
* @param array|string $payload
135-
* @param string $class
136-
* @return array
137-
*
138125
* @throws JsonException
139126
*/
140-
private function modifyMultiplePayload(array | string $payload, string $class): array
127+
private function modifyMultiplePayload(array|string $payload, string $class): array
141128
{
142129
if (! is_array($payload)) {
143130
$payload = \json_decode($payload, true, 512, JSON_THROW_ON_ERROR);
@@ -173,7 +160,7 @@ private function modifyMultiplePayload(array | string $payload, string $class):
173160
'ReceiptHandle' => $receiptHandle,
174161
'Body' => \json_encode([
175162
'uuid' => (string) Str::uuid(),
176-
'job' => $class.'@handle',
163+
'job' => $class . '@handle',
177164
'data' => $body,
178165
], JSON_THROW_ON_ERROR),
179166
'Attributes' => $attributes,
@@ -183,8 +170,6 @@ private function modifyMultiplePayload(array | string $payload, string $class):
183170
/**
184171
* @param string $payload
185172
* @param string|null $queue
186-
* @param array $options
187-
* @return mixed
188173
*
189174
* @throws JsonException
190175
*/

src/SqsQueueReaderServiceProvider.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ public function boot(): void
2020
{
2121
if ($this->app->runningInConsole()) {
2222
$this->publishes([
23-
__DIR__.'/../config/sqs-queue-reader.php' => config_path('sqs-queue-reader.php'),
23+
__DIR__ . '/../config/sqs-queue-reader.php' => config_path('sqs-queue-reader.php'),
2424
], 'config');
2525

2626
Queue::after(function (JobProcessed $event) {
2727
$connections = Config::get('queue.connections');
28-
if (in_array($event->connectionName, array_keys($connections), true)) {
28+
if (\in_array($event->connectionName, array_keys($connections), true)) {
2929
$queue = $event->job->getQueue();
3030

3131
$queueId = explode('/', $queue);
3232
$queueId = array_pop($queueId);
3333

34-
$count = (array_key_exists($queueId, Config::get('sqs-queue-reader.handlers')))
34+
$count = (\array_key_exists($queueId, Config::get('sqs-queue-reader.handlers')))
3535
? Config::get('sqs-queue-reader.handlers')[$queueId]['count']
3636
: Config::get('sqs-queue-reader.default-handler')['count'];
3737

@@ -47,7 +47,7 @@ public function boot(): void
4747

4848
public function register(): void
4949
{
50-
$this->mergeConfigFrom(__DIR__.'/../config/sqs-queue-reader.php', 'sqs-queue-reader');
50+
$this->mergeConfigFrom(__DIR__ . '/../config/sqs-queue-reader.php', 'sqs-queue-reader');
5151

5252
$this->app->booted(function () {
5353
$this->app['queue']->extend('sqs-json', static function () {

0 commit comments

Comments
 (0)