Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/rector-cs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Rector + PHP CS Fixer

on:
pull_request_target:
paths:
- 'config/**'
- 'src/**'
- 'tests/**'
- '.github/workflows/rector-cs.yml'
- 'composer.json'
- 'rector.php'
- '.php-cs-fixer.dist.php'

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
rector:
uses: yiisoft/actions/.github/workflows/rector-cs.yml@master
secrets:
token: ${{ secrets.YIISOFT_GITHUB_TOKEN }}
with:
repository: ${{ github.event.pull_request.head.repo.full_name }}
php: '8.1'
24 changes: 0 additions & 24 deletions .github/workflows/rector.yml

This file was deleted.

7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ vendor
# composer lock files
composer.lock

# PHP CS Fixer
.php_cs.cache

# PHPUnit
.phpunit.result.cache
coverage.html

# PHP CS Fixer
/.php-cs-fixer.cache
/.php-cs-fixer.php
22 changes: 22 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
use Yiisoft\CodeStyle\ConfigBuilder;

$finder = (new Finder())->in([
__DIR__ . '/config',
__DIR__ . '/src',
__DIR__ . '/tests',
]);

return ConfigBuilder::build()
->setRiskyAllowed(true)
->setParallelConfig(ParallelConfigFactory::detect())
->setRules([
'@Yiisoft/Core' => true,
'@Yiisoft/Core:risky' => true,
])
->setFinder($finder);
85 changes: 0 additions & 85 deletions .styleci.yml

This file was deleted.

3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@
"yiisoft/injector": "^1.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.93",
"maglnet/composer-require-checker": "^4.7.1",
"phpbench/phpbench": "^1.4.1",
"phpunit/phpunit": "^10.5.45",
"rector/rector": "^2.0.11",
"roave/infection-static-analysis-plugin": "^1.35",
"spatie/phpunit-watcher": "^1.24",
"vimeo/psalm": "^5.26.1 || ^6.10",
"yiisoft/code-style": "^1.0",
"yiisoft/test-support": "^3.0.2",
"yiisoft/yii-debug": "dev-master"
},
Expand Down Expand Up @@ -92,6 +94,7 @@
}
},
"scripts": {
"cs-fix": "php-cs-fixer fix",
"test": "phpunit --testdox --no-interaction",
"test-watch": "phpunit-watcher watch"
}
Expand Down
2 changes: 1 addition & 1 deletion config/di.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
],
WorkerInterface::class => QueueWorker::class,
LoopInterface::class => static function (ContainerInterface $container): LoopInterface {
return extension_loaded('pcntl')
return \extension_loaded('pcntl')
? $container->get(SignalLoop::class)
: $container->get(SimpleLoop::class);
},
Expand Down
23 changes: 8 additions & 15 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,17 @@
use Rector\Config\RectorConfig;
use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector;
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
return RectorConfig::configure()
->withPaths([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_81,
]);

$rectorConfig->skip([
])
->withPhpSets(php81: true)
->withRules([
InlineConstructorDefaultToPropertyRector::class,
])
->withSkip([
ClosureToArrowFunctionRector::class,
ReadOnlyPropertyRector::class,
]);
};
2 changes: 2 additions & 0 deletions src/Adapter/SynchronousAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
use Yiisoft\Queue\Worker\WorkerInterface;
use Yiisoft\Queue\Message\IdEnvelope;

use function count;

final class SynchronousAdapter implements AdapterInterface
{
private array $messages = [];
Expand Down
12 changes: 9 additions & 3 deletions src/Cli/SignalLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

namespace Yiisoft\Queue\Cli;

use const SIGCONT;
use const SIGHUP;
use const SIGINT;
use const SIGTERM;
use const SIGTSTP;

final class SignalLoop implements LoopInterface
{
use SoftLimitTrait;
Expand Down Expand Up @@ -33,13 +39,13 @@
public function __construct(protected int $memorySoftLimit = 0)
{
foreach (self::SIGNALS_EXIT as $signal) {
pcntl_signal($signal, fn () => $this->exit = true);
pcntl_signal($signal, fn() => $this->exit = true);
}
foreach (self::SIGNALS_SUSPEND as $signal) {
pcntl_signal($signal, fn () => $this->pause = true);
pcntl_signal($signal, fn() => $this->pause = true);
}
foreach (self::SIGNALS_RESUME as $signal) {
pcntl_signal($signal, fn () => $this->pause = false);
pcntl_signal($signal, fn() => $this->pause = false);
}
}

Expand All @@ -59,12 +65,12 @@

protected function dispatchSignals(): bool
{
pcntl_signal_dispatch();

Check warning on line 68 in src/Cli/SignalLoop.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "FunctionCallRemoval": @@ @@ protected function dispatchSignals(): bool { - pcntl_signal_dispatch(); + // Wait for resume signal until the loop is suspended while ($this->pause && !$this->exit) {

// Wait for resume signal until the loop is suspended
while ($this->pause && !$this->exit) {
usleep(10000);

Check warning on line 72 in src/Cli/SignalLoop.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "FunctionCallRemoval": @@ @@ // Wait for resume signal until the loop is suspended while ($this->pause && !$this->exit) { - usleep(10000); + pcntl_signal_dispatch(); }

Check warning on line 72 in src/Cli/SignalLoop.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "IncrementInteger": @@ @@ // Wait for resume signal until the loop is suspended while ($this->pause && !$this->exit) { - usleep(10000); + usleep(10001); pcntl_signal_dispatch(); }

Check warning on line 72 in src/Cli/SignalLoop.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": @@ @@ // Wait for resume signal until the loop is suspended while ($this->pause && !$this->exit) { - usleep(10000); + usleep(9999); pcntl_signal_dispatch(); }
pcntl_signal_dispatch();

Check warning on line 73 in src/Cli/SignalLoop.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "FunctionCallRemoval": @@ @@ // Wait for resume signal until the loop is suspended while ($this->pause && !$this->exit) { usleep(10000); - pcntl_signal_dispatch(); + } return !$this->exit;
}

return !$this->exit;
Expand Down
4 changes: 1 addition & 3 deletions src/Cli/SimpleLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ final class SimpleLoop implements LoopInterface
* @param int $memorySoftLimit Soft RAM limit in bytes. The loop won't let you continue to execute the program if
* soft limit is reached. Zero means no limit.
*/
public function __construct(protected int $memorySoftLimit = 0)
{
}
public function __construct(protected int $memorySoftLimit = 0) {}

public function canContinue(): bool
{
Expand Down
6 changes: 3 additions & 3 deletions src/Command/ListenAllCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
'Listens the all the given queues and executes messages as they come. '
. 'Meant to be used in development environment only. '
. 'Listens all configured queues by default in case you\'re using yiisoft/config. '
. 'Needs to be stopped manually.'
. 'Needs to be stopped manually.',
)]
final class ListenAllCommand extends Command
{
Expand Down Expand Up @@ -52,8 +52,8 @@
'maximum',
'm',
InputOption::VALUE_REQUIRED,
'Maximum number of messages to process in each channel before switching to another channel. ' .
'Default is 0 (no limits).',
'Maximum number of messages to process in each channel before switching to another channel. '
. 'Default is 0 (no limits).',
0,
);

Expand All @@ -69,14 +69,14 @@
}

$pauseSeconds = (int) $input->getOption('pause');
if ($pauseSeconds < 0) {

Check warning on line 72 in src/Command/ListenAllCommand.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "LessThanNegotiation": @@ @@ } $pauseSeconds = (int) $input->getOption('pause'); - if ($pauseSeconds < 0) { + if ($pauseSeconds >= 0) { $pauseSeconds = 1; }

Check warning on line 72 in src/Command/ListenAllCommand.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "LessThan": @@ @@ } $pauseSeconds = (int) $input->getOption('pause'); - if ($pauseSeconds < 0) { + if ($pauseSeconds <= 0) { $pauseSeconds = 1; }
$pauseSeconds = 1;
}

while ($this->loop->canContinue()) {
$hasMessages = false;

Check warning on line 77 in src/Command/ListenAllCommand.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "FalseValue": @@ @@ } while ($this->loop->canContinue()) { - $hasMessages = false; + $hasMessages = true; foreach ($queues as $queue) { $hasMessages = $queue->run((int) $input->getOption('maximum')) > 0 || $hasMessages; }
foreach ($queues as $queue) {
$hasMessages = $queue->run((int) $input->getOption('maximum')) > 0 || $hasMessages;

Check warning on line 79 in src/Command/ListenAllCommand.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.4-ubuntu-latest

Escaped Mutant for Mutator "GreaterThan": @@ @@ while ($this->loop->canContinue()) { $hasMessages = false; foreach ($queues as $queue) { - $hasMessages = $queue->run((int) $input->getOption('maximum')) > 0 || $hasMessages; + $hasMessages = $queue->run((int) $input->getOption('maximum')) >= 0 || $hasMessages; } if (!$hasMessages) {
}

if (!$hasMessages) {
Expand Down
4 changes: 2 additions & 2 deletions src/Command/ListenCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@

#[AsCommand(
'queue:listen',
'Listens the queue and executes messages as they come. Needs to be stopped manually.'
'Listens the queue and executes messages as they come. Needs to be stopped manually.',
)]
final class ListenCommand extends Command
{
public function __construct(
private readonly QueueProviderInterface $queueProvider
private readonly QueueProviderInterface $queueProvider,
) {
parent::__construct();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Command/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#[AsCommand(
'queue:run',
'Runs all the existing messages in the given queues. Exits once messages are over.'
'Runs all the existing messages in the given queues. Exits once messages are over.',
)]
final class RunCommand extends Command
{
Expand Down Expand Up @@ -50,7 +50,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->write("Processing channel $channel... ");
$count = $this->queueProvider
->get($channel)
->run((int)$input->getOption('maximum'));
->run((int) $input->getOption('maximum'));

$output->writeln("Messages processed: $count.");
}
Expand Down
20 changes: 11 additions & 9 deletions src/Debug/QueueCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Yiisoft\Queue\Middleware\Push\MiddlewarePushInterface;
use Yiisoft\Queue\QueueInterface;

use function count;

final class QueueCollector implements SummaryCollectorInterface
{
use CollectorTrait;
Expand Down Expand Up @@ -70,27 +72,27 @@ public function collectWorkerProcessing(MessageInterface $message, QueueInterfac
$this->processingMessages[$queue->getChannel()][] = $message;
}

private function reset(): void
{
$this->pushes = [];
$this->statuses = [];
$this->processingMessages = [];
}

public function getSummary(): array
{
if (!$this->isActive()) {
return [];
}

$countPushes = array_sum(array_map(static fn ($messages) => is_countable($messages) ? count($messages) : 0, $this->pushes));
$countPushes = array_sum(array_map(static fn($messages) => is_countable($messages) ? count($messages) : 0, $this->pushes));
$countStatuses = count($this->statuses);
$countProcessingMessages = array_sum(array_map(static fn ($messages) => is_countable($messages) ? count($messages) : 0, $this->processingMessages));
$countProcessingMessages = array_sum(array_map(static fn($messages) => is_countable($messages) ? count($messages) : 0, $this->processingMessages));

return [
'countPushes' => $countPushes,
'countStatuses' => $countStatuses,
'countProcessingMessages' => $countProcessingMessages,
];
}

private function reset(): void
{
$this->pushes = [];
$this->statuses = [];
$this->processingMessages = [];
}
}
Loading
Loading