diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md deleted file mode 100644 index 63031f9153..0000000000 --- a/.github/ISSUE_TEMPLATE.md +++ /dev/null @@ -1,19 +0,0 @@ - - -### What steps will reproduce the problem? - -### What's expected? - -### What do you get instead? - - -### Additional info - -| Q | A -| ---------------- | --- -| Yii version | -| PHP version | -| Operating system | diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md deleted file mode 100644 index cecccf6dcf..0000000000 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ /dev/null @@ -1,6 +0,0 @@ -| Q | A -| ------------- | --- -| Is bugfix? | ✔️/❌ -| New feature? | ✔️/❌ -| Breaks BC? | ✔️/❌ -| Fixed issues | diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000000..a5a8c2d533 --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,28 @@ +name: linter + +permissions: + contents: read + +on: + pull_request: &ignore-paths + paths-ignore: + - ".editorconfig" + - ".gitattributes" + - ".github/CONTRIBUTING.md" + - ".github/FUNDING.yml" + - ".github/SECURITY.md" + - ".gitignore" + - "docker-compose.yml" + - "LICENSE.md" + - "README.md" + - "CHANGELOG.md" + - "UPGRADE.md" + + push: *ignore-paths + +jobs: + phpcs: + uses: yiisoft/yii2-actions/.github/workflows/linter.yml@master + with: + directories: src/ tests/ + extensions: 'amqp' diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a0c1a0f68b..8574a233c0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,9 +1,8 @@ ---- name: build on: pull_request: - paths-ignore: + paths-ignore: &ignore-paths - 'docs/**' - 'README.md' - 'CHANGELOG.md' @@ -13,13 +12,7 @@ on: push: branches: [ 'master' ] - paths-ignore: - - 'docs/**' - - 'README.md' - - 'CHANGELOG.md' - - 'UPGRADE.md' - - '.gitignore' - - '.gitattributes' + paths-ignore: *ignore-paths env: COMPOSE_PROJECT_NAME: yii2-queue diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 9e5e160bbf..10d5f6e675 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -1,7 +1,6 @@ ---- on: pull_request: - paths-ignore: + paths-ignore: &ignore-paths - 'docs/**' - 'README.md' - 'CHANGELOG.md' @@ -12,14 +11,7 @@ on: push: branches: [ 'master' ] - paths-ignore: - - 'docs/**' - - 'README.md' - - 'CHANGELOG.md' - - 'UPGRADE.md' - - '.gitignore' - - '.gitattributes' - - 'phpunit.xml.dist' + paths-ignore: *ignore-paths name: static analysis diff --git a/CHANGELOG.md b/CHANGELOG.md index aacfa92966..1384e485ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,16 +3,17 @@ Yii2 Queue Extension Change Log 3.0.0 under development --- -- The minimum supported PHP version is 8.3 (@s1lver) -- Added PSALM for static code analysis. Error level set to 1 (@s1lver) -- Added strict typing (@s1lver) -- The `pda/pheanstalk` package of the Beanstalk driver has been updated to version 8.* (@s1lver) -- Removed deprecated interfaces `RetryableJob`, `Job`, `Serializer` (@s1lver) -- Removed deprecated classes `Signal`, `Verbose` (@s1lver) -- Deprecated driver amqp has been removed (@s1lver) -- Returned tests for the SQS driver (@s1lver) -- All dependent packages for supported drivers have been updated to the latest versions (@s1lver) -- The `opis/closure` package did not support PHP 8.1 and was replaced by the `laravel/serializable-closure` package (@s1lver) +- Enh #542: The minimum supported PHP version is 8.3 (@s1lver) +- Enh #503: Added PSALM for static code analysis. Error level set to 1 (@s1lver) +- Enh #503: Added strict typing (@s1lver) +- Enh #542: The `pda/pheanstalk` package of the Beanstalk driver has been updated to version 8.* (@s1lver) +- Enh #503: Removed deprecated interfaces `RetryableJob`, `Job`, `Serializer` (@s1lver) +- Enh #503: Removed deprecated classes `Signal`, `Verbose` (@s1lver) +- Enh #503: Deprecated driver amqp has been removed (@s1lver) +- Enh #542: Returned tests for the SQS driver (@s1lver) +- Enh #503: All dependent packages for supported drivers have been updated to the latest versions (@s1lver) +- Enh #503: The `opis/closure` package did not support PHP 8.1 and was replaced by the `laravel/serializable-closure` package (@s1lver) +- Enh #544: Applying Yii2 coding standards (@s1lver) 2.3.8 January 08, 2026 ---------------------- diff --git a/composer.json b/composer.json index 602789f7c2..14ea134433 100644 --- a/composer.json +++ b/composer.json @@ -26,6 +26,7 @@ "yiisoft/yii2-redis": "~2.1.0", "yiisoft/yii2-debug": "~2.1.0", "yiisoft/yii2-gii": "~2.2.0", + "yiisoft/yii2-coding-standards": "^3.0", "php-amqplib/php-amqplib": "^3.0.0", "enqueue/amqp-lib": "^0.10.0", "enqueue/amqp-bunny": "^0.10.0", @@ -80,5 +81,9 @@ "type": "composer", "url": "https://asset-packagist.org" } - ] + ], + "scripts": { + "phpcbf": "./vendor/bin/phpcbf -q src/ tests/", + "phpcs": "./vendor/bin/phpcs -q src/ tests/" + } } diff --git a/phpcs.xml.dist b/phpcs.xml.dist new file mode 100644 index 0000000000..0e2c510615 --- /dev/null +++ b/phpcs.xml.dist @@ -0,0 +1,21 @@ + + + + + + + + + /src/ + /tests/ + + + /gii/form\.php$ + + + /gii/default/job\.php$ + + + /tests/ + + diff --git a/src/ExecEvent.php b/src/ExecEvent.php index b59b9dafd0..3af014c4ce 100644 --- a/src/ExecEvent.php +++ b/src/ExecEvent.php @@ -1,13 +1,13 @@ unserializeMessage($message); // Handle aborted jobs without throwing an error. - if ($attempt > 1 && - (($job instanceof RetryableJobInterface && !$job->canRetry($attempt - 1, $error)) - || (!($job instanceof RetryableJobInterface) && $attempt > $this->attempts))) { + if ( + $attempt > 1 + && (($job instanceof RetryableJobInterface && !$job->canRetry($attempt - 1, $error)) + || (!($job instanceof RetryableJobInterface) && $attempt > $this->attempts)) + ) { return true; } $event = new ExecEvent([ diff --git a/src/RetryableJobInterface.php b/src/RetryableJobInterface.php index f61ec269b5..147a0aa41b 100644 --- a/src/RetryableJobInterface.php +++ b/src/RetryableJobInterface.php @@ -1,13 +1,13 @@ command->stdout(' - ', BaseConsole::FG_YELLOW); $this->command->stdout('Done', BaseConsole::FG_GREEN); $duration = number_format(round(microtime(true) - $this->jobStartedAt, 3), 3); - $memory = round(memory_get_peak_usage()/1024/1024, 2); + $memory = round(memory_get_peak_usage() / 1024 / 1024, 2); $this->command->stdout(" ($duration s, $memory MiB)", BaseConsole::FG_YELLOW); $this->command->stdout(PHP_EOL); } diff --git a/src/cli/WorkerEvent.php b/src/cli/WorkerEvent.php index 530c8ebd59..15aa1ae77b 100644 --- a/src/cli/WorkerEvent.php +++ b/src/cli/WorkerEvent.php @@ -1,13 +1,13 @@ isDone($job['id'])) { $job['status'] = 'done'; } - } catch (NotSupportedException|Exception $e) { + } catch (NotSupportedException | Exception $e) { $job['status'] = $e->getMessage(); } } diff --git a/src/drivers/amqp_interop/Command.php b/src/drivers/amqp_interop/Command.php index b24f1cc252..dcb9ce2451 100644 --- a/src/drivers/amqp_interop/Command.php +++ b/src/drivers/amqp_interop/Command.php @@ -1,13 +1,13 @@ setProperty(self::ATTEMPT, ++$attempt); $this->context->createProducer()->send( - $this->context->createQueue($this->queueName), - $newMessage - ); + $this->context->createQueue($this->queueName), + $newMessage + ); } private function createQueue(): AmqpQueue diff --git a/src/drivers/beanstalk/Command.php b/src/drivers/beanstalk/Command.php index 2df4e720a7..4d7e272b76 100644 --- a/src/drivers/beanstalk/Command.php +++ b/src/drivers/beanstalk/Command.php @@ -1,13 +1,13 @@ statsJob($job); - if ($this->handleMessage( - $job->getId(), - $job->getData(), - $info->timeToRelease, - $info->reserves - )) { + if ( + $this->handleMessage( + $job->getId(), + $job->getData(), + $info->timeToRelease, + $info->reserves + ) + ) { $pheanstalk->delete($job); } } catch (Exception) { diff --git a/src/drivers/db/Command.php b/src/drivers/db/Command.php index 4978bdd7f2..bb873996e1 100644 --- a/src/drivers/db/Command.php +++ b/src/drivers/db/Command.php @@ -1,13 +1,13 @@ reserve()) { /** @psalm-var array{id: int|string, job:string, ttr:int|string, attempt:int|string} $payload */ - if ($this->handleMessage( - $payload['id'], - $payload['job'], - (int) $payload['ttr'], - (int) $payload['attempt'] - )) { + if ( + $this->handleMessage( + $payload['id'], + $payload['job'], + (int) $payload['ttr'], + (int) $payload['attempt'] + ) + ) { $this->release($payload); } } elseif (!$repeat) { @@ -176,7 +178,7 @@ protected function pushMessage(string $payload, int $ttr, int $delay, mixed $pri if (null === $tableSchema) { return null; } - return $this->getDb()->getLastInsertID($tableSchema->sequenceName??''); + return $this->getDb()->getLastInsertID($tableSchema->sequenceName ?? ''); } /** diff --git a/src/drivers/db/StatisticsProvider.php b/src/drivers/db/StatisticsProvider.php index c5d0f3a9bf..6c77882057 100644 --- a/src/drivers/db/StatisticsProvider.php +++ b/src/drivers/db/StatisticsProvider.php @@ -1,13 +1,13 @@ messages = $response['Messages']??[]; + $this->messages = $response['Messages'] ?? []; if (!empty($this->messages)) { $messages = $this->messages; /** @var array{ diff --git a/src/drivers/sqs/Queue.php b/src/drivers/sqs/Queue.php index c2e6c0aa73..2dc93af672 100644 --- a/src/drivers/sqs/Queue.php +++ b/src/drivers/sqs/Queue.php @@ -1,13 +1,13 @@ getClient()->sendMessage($request); - return null === $response['MessageId']?null:(string)$response['MessageId']; + return null === $response['MessageId'] ? null : (string)$response['MessageId']; } /** diff --git a/src/drivers/stomp/Command.php b/src/drivers/stomp/Command.php index 974a0d1c31..da42357a06 100644 --- a/src/drivers/stomp/Command.php +++ b/src/drivers/stomp/Command.php @@ -1,13 +1,13 @@ jobClass . '.php', + $alias . '/' . $this->jobClass . '.php', $this->render('job.php', $params) ); diff --git a/src/interfaces/DelayedCountInterface.php b/src/interfaces/DelayedCountInterface.php index fcf19fd222..1fa82cf5f7 100644 --- a/src/interfaces/DelayedCountInterface.php +++ b/src/interfaces/DelayedCountInterface.php @@ -1,13 +1,13 @@ modes[$mode] as $queueName => $workerCommand) { @@ -96,7 +96,6 @@ public function run(string $mode = 'fast', int $jobCount = 1000, int $workerCoun $pushedCount = 0; while ($pushedCount < $jobCount) { - // Push batch of jobs $jobs = []; for ($i = 0; $i < $workerCount && $pushedCount < $jobCount; $i++) { diff --git a/tests/app/benchmark/waiting/Job.php b/tests/app/benchmark/waiting/Job.php index 0337ebe2b8..8dcd237772 100644 --- a/tests/app/benchmark/waiting/Job.php +++ b/tests/app/benchmark/waiting/Job.php @@ -1,13 +1,13 @@ getErrorOutput(); $this->assertEmpty( $error, - "Can not execute " . implode($cmd) . " command:\n$error" + 'Can not execute ' . implode($cmd) . " command:\n$error" ); } diff --git a/tests/drivers/TestCase.php b/tests/drivers/TestCase.php index 287447ca81..4a7feb34ee 100644 --- a/tests/drivers/TestCase.php +++ b/tests/drivers/TestCase.php @@ -1,13 +1,13 @@ getQueue()->messageHandler = null; - foreach (glob(Yii::getAlias("@runtime/queue/*")) as $fileName) { + foreach (glob(Yii::getAlias('@runtime/queue/*')) as $fileName) { unlink($fileName); } parent::tearDown(); diff --git a/tests/drivers/gearman/QueueTest.php b/tests/drivers/gearman/QueueTest.php index c47e30e746..ccfab02e3f 100644 --- a/tests/drivers/gearman/QueueTest.php +++ b/tests/drivers/gearman/QueueTest.php @@ -1,13 +1,13 @@ getQueue()->delay(1)->push($job); // Expect a single message to be received. $messageCount = 0; - $this->getQueue()->messageHandler = static function () use(&$messageCount) { + $this->getQueue()->messageHandler = static function () use (&$messageCount) { $messageCount++; return true; }; diff --git a/tests/drivers/redis/RedisCrashMock.php b/tests/drivers/redis/RedisCrashMock.php index b332d6abec..2f135110bc 100644 --- a/tests/drivers/redis/RedisCrashMock.php +++ b/tests/drivers/redis/RedisCrashMock.php @@ -1,5 +1,11 @@