Skip to content

Commit 64d5f86

Browse files
committed
add linter + fix php 8.4 warning + min php 8.3
1 parent c12a7e9 commit 64d5f86

File tree

12 files changed

+118
-124
lines changed

12 files changed

+118
-124
lines changed

.github/workflows/php.yml

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

.github/workflows/pint.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: PHP Linting
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
phplint:
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- name: "laravel-pint"
20+
uses: aglipanci/[email protected]
21+
with:
22+
testMode: true
23+
verboseMode: true
24+
configPath: "pint.json"

composer.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313
}
1414
],
1515
"require": {
16-
"yiisoft/yii2-queue": "^2.0",
16+
"php": "^8.3",
17+
"nesbot/carbon": "^2.0 | ^3.0",
1718
"yiisoft/yii2-httpclient": "^2.0",
18-
"nesbot/carbon": "^2.0 | ^3.0"
19+
"yiisoft/yii2-queue": "^2.0"
1920
},
2021
"require-dev": {
21-
"roave/security-advisories": "dev-latest"
22+
"roave/security-advisories": "dev-latest",
23+
"rector/rector": "^2.1",
24+
"laravel/pint": "^1.24"
2225
},
2326
"autoload": {
2427
"psr-4": {
@@ -34,6 +37,7 @@
3437
}
3538
],
3639
"config": {
40+
"sort-packages": true,
3741
"allow-plugins": {
3842
"yiisoft/yii2-composer": true
3943
}

pint.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"preset": "empty",
3+
"rules": {
4+
"@PhpCsFixer": true,
5+
"ordered_class_elements": {
6+
"sort_algorithm": "alpha"
7+
},
8+
"list_syntax": {
9+
"syntax": "short"
10+
},
11+
"concat_space": {
12+
"spacing": "one"
13+
},
14+
"ternary_to_null_coalescing": true,
15+
"multiline_whitespace_before_semicolons": {
16+
"strategy": "no_multi_line"
17+
}
18+
}
19+
}

rector.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
7+
return RectorConfig::configure()
8+
->withPaths([
9+
__DIR__ . '/src',
10+
])
11+
->withPhpSets(php84: true)
12+
->withPreparedSets(
13+
deadCode: true,
14+
codeQuality: true,
15+
typeDeclarations: true,
16+
instanceOf: true
17+
);

src/AzureJobInterface.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@
44

55
interface AzureJobInterface
66
{
7-
// region Getters/Setters
87
public function getQueue(): ?string;
9-
// endregion Getters/Setters
10-
}
8+
}

src/Command.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,13 @@
99
*/
1010
class Command extends CliCommand
1111
{
12-
// region Controllers Actions
1312
public function actionListen(?string $queue = null): void
1413
{
1514
$this->queue->run(true, $queue);
1615
}
17-
// endregion Controllers Actions
1816

19-
// region Protected Methods
2017
protected function isWorkerAction($actionID): bool
2118
{
22-
return $actionID === 'listen';
19+
return 'listen' === $actionID;
2320
}
24-
// endregion Protected Methods
2521
}

src/Queue.php

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
class Queue extends \yii\queue\cli\Queue
1414
{
15-
// region Public Properties
1615
/**
1716
* use this property to filter job execution on a specific id
1817
* You can use this property when you need to run multiple environments with the same queue at the same time, multiple locals environments for example.
@@ -21,16 +20,16 @@ class Queue extends \yii\queue\cli\Queue
2120
*/
2221
public ?string $id = null;
2322
public string $queue = 'default';
23+
2424
/** @var ServiceBus[] */
2525
public array $queues = [
2626
'default' => 'serviceBus',
2727
];
28-
// endregion Public Properties
2928

30-
// region Initialization
3129
/**
32-
* @throws \yii\base\InvalidConfigException
30+
* @throws InvalidConfigException
3331
*/
32+
#[\Override]
3433
public function init(): void
3534
{
3635
parent::init();
@@ -41,9 +40,8 @@ public function init(): void
4140
$this->queues[$queue] = Instance::ensure($config, ServiceBus::class);
4241
}
4342
}
44-
// endregion Initialization
4543

46-
// region Public Methods
44+
#[\Override]
4745
public function push($job): ?string
4846
{
4947
$defaultQueue = $this->queue;
@@ -67,11 +65,13 @@ public function push($job): ?string
6765
/**
6866
* Listens queue and runs each job.
6967
*
70-
* @param bool $repeat whether to continue listening when queue is empty.
71-
* @param int $timeout number of seconds to wait for next message.
68+
* @param bool $repeat whether to continue listening when queue is empty
69+
* @param int $timeout number of seconds to wait for next message
70+
*
71+
* @return null|int exit code
72+
*
73+
* @internal for worker command only
7274
*
73-
* @return null|int exit code.
74-
* @internal for worker command only.
7575
* @since 2.0.2
7676
*/
7777
public function run(bool $repeat, ?string $queue = null, int $timeout = 30): ?int
@@ -83,15 +83,12 @@ public function run(bool $repeat, ?string $queue = null, int $timeout = 30): ?in
8383
* @param string $id of a job message
8484
*
8585
* @throws NotSupportedException
86-
* @return void status code
8786
*/
8887
public function status($id): void
8988
{
9089
throw new NotSupportedException('Status is not supported in the driver.');
9190
}
92-
// endregion Public Methods
9391

94-
// region Protected Methods
9592
/**
9693
* @throws Exception
9794
* @throws InvalidConfigException
@@ -102,7 +99,7 @@ protected function processWorker(callable $canContinue, bool $repeat, string $qu
10299
while ($canContinue()) {
103100
$message = $this->queues[$queue]->receiveMessage(ServiceBus::PEEK_LOCK, $timeout);
104101

105-
if ($message !== null && $message->brokerProperties !== null) {
102+
if (null !== $message && null !== $message->brokerProperties) {
106103
if ($message->brokerProperties->to && !$message->brokerProperties->isTo($this->id)) {
107104
continue;
108105
}
@@ -116,14 +113,15 @@ protected function processWorker(callable $canContinue, bool $repeat, string $qu
116113
}
117114

118115
/**
119-
* @param $message
120-
* @param int $ttr time to reserve in seconds
116+
* @param int $ttr time to reserve in seconds
121117
* @param int $delay
122118
* @param mixed $priority
119+
* @param mixed $message
123120
*
124-
* @throws \JsonException
125-
* @throws \yii\httpclient\Exception
126121
* @return string id of a job message
122+
*
123+
* @throws \JsonException
124+
* @throws Exception
127125
*/
128126
protected function pushMessage($message, $ttr, $delay, $priority): string
129127
{
@@ -137,5 +135,4 @@ protected function pushMessage($message, $ttr, $delay, $priority): string
137135

138136
return $azureMessage->brokerProperties->messageId;
139137
}
140-
// endregion Protected Methods
141138
}

src/service/BrokerProperties.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
class BrokerProperties implements \JsonSerializable
88
{
9-
// region Initialization
109
public function __construct(
1110
public ?string $correlationId = null,
1211
public ?string $sessionId = null,
@@ -23,20 +22,11 @@ public function __construct(
2322
public ?string $replyToSessionId = null,
2423
public ?string $partitionKey = null,
2524
) {
26-
if ($this->messageId === null) {
25+
if (null === $this->messageId) {
2726
$this->messageId = uniqid('', true);
2827
}
2928
}
30-
// endregion Initialization
3129

32-
// region Getters/Setters
33-
public function setDelay(int $value): void
34-
{
35-
$this->scheduledEnqueueTimeUtc = Carbon::now('UTC')->addSeconds($value);
36-
}
37-
// endregion Getters/Setters
38-
39-
// region Public Methods
4030
public function isTo(string $id): bool
4131
{
4232
return $this->to === $id;
@@ -56,5 +46,9 @@ public function jsonSerialize(): mixed
5646
'PartitionKey' => $this->partitionKey,
5747
]);
5848
}
59-
// endregion Public Methods
49+
50+
public function setDelay(int $value): void
51+
{
52+
$this->scheduledEnqueueTimeUtc = Carbon::now('UTC')->addSeconds($value);
53+
}
6054
}

src/service/Message.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,15 @@
66

77
class Message
88
{
9-
// region Initialization
109
public function __construct(
1110
public ?string $body,
1211
public ?string $contentType = 'application/vnd.microsoft.servicebus.yml',
1312
public ?Carbon $date = null,
1413
public ?string $location = null,
1514
public ?BrokerProperties $brokerProperties = null,
1615
public array $properties = [],
17-
) {
18-
}
19-
// endregion Initialization
16+
) {}
2017

21-
// region Getters/Setters
2218
public function getProperty(string $propertyName): mixed
2319
{
2420
return $this->properties[strtolower($propertyName)] ?? null;
@@ -28,5 +24,4 @@ public function setProperty(string $propertyName, mixed $propertyValue): void
2824
{
2925
$this->properties[strtolower($propertyName)] = $propertyValue;
3026
}
31-
// endregion Getters/Setters
3227
}

0 commit comments

Comments
 (0)