diff --git a/README.md b/README.md index 0611d2a..019b933 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,8 @@ The queue system uses logs to ensure maintainability and implements retry featur ## Version History -| Branch | Release | PSR-11 | OSS Lifecycle | PHP Version | -|--------|---------|--------|----------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------| +| Branch | Release | PSR-11 | OSS Lifecycle | PHP Version | +|--------|---------|--------|-----------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------| | 2.0 | `> 2.0` | 1 | ![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/queue) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/queue/2.0.0) | | 1.0 | `< 2.0` | 1 | ![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/queue) | ![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/queue/1.0.0) | diff --git a/composer.json b/composer.json index 479b3bc..7bde9e8 100644 --- a/composer.json +++ b/composer.json @@ -62,6 +62,9 @@ "roave/security-advisories": "dev-master", "swoole/ide-helper": "~6.0.0" }, + "conflict": { + "symfony/polyfill-php83": "<1.30" + }, "autoload": { "psr-4": { "Queue\\": "src/" diff --git a/src/App/Message/Message.php b/src/App/Message/Message.php index 2ac080b..68c5874 100644 --- a/src/App/Message/Message.php +++ b/src/App/Message/Message.php @@ -7,17 +7,7 @@ class Message { public function __construct( - private array $payload, + public array $payload, ) { } - - public function getPayload(): array - { - return $this->payload; - } - - public function setPayload(array $payload): void - { - $this->payload = $payload; - } } diff --git a/src/App/Message/MessageHandler.php b/src/App/Message/MessageHandler.php index 39a0d2b..0a505cb 100644 --- a/src/App/Message/MessageHandler.php +++ b/src/App/Message/MessageHandler.php @@ -28,7 +28,7 @@ public function __construct( */ public function __invoke(Message $message): void { - $payload = $message->getPayload(); + $payload = $message->payload; try { if ($payload['foo'] === 'control') { @@ -52,7 +52,7 @@ public function __invoke(Message $message): void } $payload['retry_count'] = $retryCount + 1; - $message->setPayload($payload); + $message->payload = $payload; throw $e; } diff --git a/src/Swoole/Command/StartCommand.php b/src/Swoole/Command/StartCommand.php index c1eb1cd..8651703 100644 --- a/src/Swoole/Command/StartCommand.php +++ b/src/Swoole/Command/StartCommand.php @@ -24,9 +24,9 @@ class StartCommand extends Command public PidManager $pidManager; - public const DEFAULT_PROCESS_NAME = 'dotkernel-queue'; + public const string DEFAULT_PROCESS_NAME = 'dotkernel-queue'; - public const HELP = <<<'EOH' + public const string HELP = <<<'EOH' Start the web server. If --daemonize is provided, starts the server as a background process and returns handling to the shell; otherwise, the server runs in the current process. diff --git a/src/Swoole/Command/StopCommand.php b/src/Swoole/Command/StopCommand.php index b64d2b3..b9b530b 100644 --- a/src/Swoole/Command/StopCommand.php +++ b/src/Swoole/Command/StopCommand.php @@ -18,7 +18,7 @@ class StopCommand extends Command { use IsRunningTrait; - public const HELP = <<<'EOH' + public const string HELP = <<<'EOH' Stop the web server. Kills all worker processes and stops the web server. This command is only relevant when the server was started using the diff --git a/src/Swoole/PidManager.php b/src/Swoole/PidManager.php index 427d529..19a3c1d 100644 --- a/src/Swoole/PidManager.php +++ b/src/Swoole/PidManager.php @@ -17,7 +17,7 @@ class PidManager { - public function __construct(private string $pidFile) + public function __construct(private readonly string $pidFile) { } diff --git a/src/Swoole/ServerFactory.php b/src/Swoole/ServerFactory.php index 5f7a59f..0f5be88 100644 --- a/src/Swoole/ServerFactory.php +++ b/src/Swoole/ServerFactory.php @@ -31,22 +31,16 @@ class ServerFactory { - /** - * @var string - */ - public const DEFAULT_HOST = '127.0.0.1'; + public const string DEFAULT_HOST = '127.0.0.1'; - /** - * @var int - */ - public const DEFAULT_PORT = 8080; + public const int DEFAULT_PORT = 8080; /** * Swoole server supported modes * * @var int[] */ - private const MODES = [ + private const array MODES = [ SWOOLE_BASE, SWOOLE_PROCESS, ]; @@ -56,7 +50,7 @@ class ServerFactory * * @var int[] */ - private const PROTOCOLS = [ + private const array PROTOCOLS = [ SWOOLE_SOCK_TCP, SWOOLE_SOCK_TCP6, SWOOLE_SOCK_UDP, diff --git a/test/App/Message/MessageHandlerTest.php b/test/App/Message/MessageHandlerTest.php index 4c2277a..e33d14a 100644 --- a/test/App/Message/MessageHandlerTest.php +++ b/test/App/Message/MessageHandlerTest.php @@ -65,7 +65,7 @@ public function testControlMessageDoesNotThrowAndDoesNotSetRetryCount(): void $message = new Message(['foo' => 'control']); $handler($message); - $payload = $message->getPayload(); + $payload = $message->payload; $this->assertArrayNotHasKey('retry_count', $payload); } @@ -81,7 +81,7 @@ public function testRetryMessageThrowsExceptionAndSetsRetryCount(): void try { $handler($message); } finally { - $payload = $message->getPayload(); + $payload = $message->payload; $this->assertArrayHasKey('retry_count', $payload); $this->assertEquals(1, $payload['retry_count']); // first retry } @@ -101,7 +101,7 @@ public function testRetryMessageWithExistingRetryCountIncrementsIt(): void try { $handler($message); } finally { - $payload = $message->getPayload(); + $payload = $message->payload; $this->assertEquals(3, $payload['retry_count']); // incremented from 2 → 3 } } diff --git a/test/App/Message/MessageTest.php b/test/App/Message/MessageTest.php index 8c733a6..3f9d317 100644 --- a/test/App/Message/MessageTest.php +++ b/test/App/Message/MessageTest.php @@ -12,6 +12,6 @@ class MessageTest extends TestCase public function testMessageAccessors(): void { $admin = new Message(['payload' => 'test message payload']); - $this->assertSame(['payload' => 'test message payload'], $admin->getPayload()); + $this->assertSame(['payload' => 'test message payload'], $admin->payload); } } diff --git a/test/Swoole/Delegators/TCPServerDelegatorTest.php b/test/Swoole/Delegators/TCPServerDelegatorTest.php index 15d690e..1f419b2 100644 --- a/test/Swoole/Delegators/TCPServerDelegatorTest.php +++ b/test/Swoole/Delegators/TCPServerDelegatorTest.php @@ -132,10 +132,10 @@ public function testReceiveDispatchesMessagesAndLogsWhenUnknownCommand(): void if ($callCount === 1) { $this->assertInstanceOf(Message::class, $message); - $this->assertEquals('hello', $message->getPayload()['foo']); + $this->assertEquals('hello', $message->payload['foo']); } elseif ($callCount === 2) { $this->assertInstanceOf(Message::class, $message); - $this->assertEquals('with 5 seconds delay', $message->getPayload()['foo']); + $this->assertEquals('with 5 seconds delay', $message->payload['foo']); } else { $this->fail('dispatch called more than twice'); }