diff --git a/bin/code-style.sh b/bin/code-style.sh index b94e7ab..24b397d 100755 --- a/bin/code-style.sh +++ b/bin/code-style.sh @@ -5,6 +5,11 @@ cd $(dirname $0)/.. ARG="$1" [[ $ARG == "--fix" ]] && COMMAND="fix" || COMMAND="check" +# php-cs-fixer may lag behind with supporting newest versions of PHP and +# would complain when running under them, which would needlessly fail our +# GitHub Action. So we'll tell php-cs-fixer to skip that check. +export PHP_CS_FIXER_IGNORE_ENV=1 + ./vendor/bin/php-cs-fixer $COMMAND --diff -vvv EXITCODE=$? diff --git a/src/AsyncResult.php b/src/AsyncResult.php index 3298ea7..e3758a6 100644 --- a/src/AsyncResult.php +++ b/src/AsyncResult.php @@ -4,12 +4,11 @@ namespace Smuuf\CeleryForPhp; -use Smuuf\CeleryForPhp\TaskMetaResult; use Smuuf\CeleryForPhp\Exc\RuntimeException; use Smuuf\CeleryForPhp\Exc\CeleryTaskException; use Smuuf\CeleryForPhp\Exc\CeleryTimeoutException; use Smuuf\CeleryForPhp\Exc\InvalidArgumentException; -use Smuuf\CeleryForPhp\Helpers\Functions as Functions; +use Smuuf\CeleryForPhp\Helpers\Functions; use Smuuf\CeleryForPhp\Helpers\Signals; use Smuuf\CeleryForPhp\Interfaces\IAsyncResult; use Smuuf\CeleryForPhp\Interfaces\IResultBackend; diff --git a/src/Config.php b/src/Config.php index 8f8b287..a633c2c 100644 --- a/src/Config.php +++ b/src/Config.php @@ -14,10 +14,16 @@ class Config { use StrictObject; public static function createDefault(): self { - return new self; + return new self(); } /** + * @param int $taskMessageProtocolVersion + * Celery task message protocol version to use. + * See https://docs.celeryq.dev/en/stable/internals/protocol.html + * @param ISerializer $taskSerializer + * Serializer to use when serializing task message body. If not + * specified, `JsonSerializer` is used by default. * @param null|ITaskIdFactory $taskIdFactory * Optional custom task ID builder. If not specified, a default * factory will be used. @@ -25,12 +31,6 @@ public static function createDefault(): self { * Name of the Celery control exchange (used for sending control commands, * such as 'revoke', to Celery workers). * Default value is 'celery' but can be specified to some other name. - * @param int $taskMessageProtocolVersion - * Celery task message protocol version to use. - * See https://docs.celeryq.dev/en/stable/internals/protocol.html - * @param ISerializer $taskSerializer - * Serializer to use when serializing task message body. If not - * specified, `JsonSerializer` is used by default. */ public function __construct( private int $taskMessageProtocolVersion = MessageBuilder::MESSAGE_PROTOCOL_V2, diff --git a/src/Exc/CeleryTimeoutException.php b/src/Exc/CeleryTimeoutException.php index c814819..c10029f 100644 --- a/src/Exc/CeleryTimeoutException.php +++ b/src/Exc/CeleryTimeoutException.php @@ -2,6 +2,4 @@ namespace Smuuf\CeleryForPhp\Exc; -class CeleryTimeoutException extends \RuntimeException implements ICeleryForPhpException { - -} +class CeleryTimeoutException extends \RuntimeException implements ICeleryForPhpException {} diff --git a/src/Exc/ICeleryForPhpException.php b/src/Exc/ICeleryForPhpException.php index 31a9d7c..691c6be 100644 --- a/src/Exc/ICeleryForPhpException.php +++ b/src/Exc/ICeleryForPhpException.php @@ -2,6 +2,4 @@ namespace Smuuf\CeleryForPhp\Exc; -interface ICeleryForPhpException extends \Throwable { - -} +interface ICeleryForPhpException extends \Throwable {} diff --git a/src/Exc/InvalidArgumentException.php b/src/Exc/InvalidArgumentException.php index 00f4b00..0def2e0 100644 --- a/src/Exc/InvalidArgumentException.php +++ b/src/Exc/InvalidArgumentException.php @@ -2,6 +2,4 @@ namespace Smuuf\CeleryForPhp\Exc; -class InvalidArgumentException extends \LogicException implements ICeleryForPhpException { - -} +class InvalidArgumentException extends \LogicException implements ICeleryForPhpException {} diff --git a/src/Exc/RuntimeException.php b/src/Exc/RuntimeException.php index 0dcad38..aa1e1f4 100644 --- a/src/Exc/RuntimeException.php +++ b/src/Exc/RuntimeException.php @@ -2,6 +2,4 @@ namespace Smuuf\CeleryForPhp\Exc; -class RuntimeException extends \RuntimeException implements ICeleryForPhpException { - -} +class RuntimeException extends \RuntimeException implements ICeleryForPhpException {} diff --git a/src/Helpers/Functions.php b/src/Helpers/Functions.php index 5b0c5db..208768f 100644 --- a/src/Helpers/Functions.php +++ b/src/Helpers/Functions.php @@ -15,16 +15,16 @@ public static function monotonicTime(): float { /** * Build a random UUID v4. - * Thanks to https://stackoverflow.com/a/15875555/1285669 + * Thanks to https://stackoverflow.com/a/15875555/1285669. */ public static function uuid4(): string { $data = random_bytes(16); // Set version to 01006. - $data[6] = chr(ord($data[6]) & 0x0f | 0x40); + $data[6] = chr(ord($data[6]) & 0x0F | 0x40); // Set bits 6-7 to 10. - $data[8] = chr(ord($data[8]) & 0x3f | 0x80); + $data[8] = chr(ord($data[8]) & 0x3F | 0x80); // Output the 36 character UUID. return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)); diff --git a/src/Messaging/MessageBuilder.php b/src/Messaging/MessageBuilder.php index b2ced8b..1eb6622 100644 --- a/src/Messaging/MessageBuilder.php +++ b/src/Messaging/MessageBuilder.php @@ -68,7 +68,7 @@ public function buildControlMessage( 'body_encoding' => 'base64', 'delivery_mode' => 2, 'delivery_tag' => Functions::uuid4(), - 'priority' => 0 + 'priority' => 0, ]; return new CeleryMessage($headers, $properties, $body, $this->serializer); diff --git a/src/TaskMetaResult.php b/src/TaskMetaResult.php index 6d9ac9a..b5da374 100644 --- a/src/TaskMetaResult.php +++ b/src/TaskMetaResult.php @@ -74,8 +74,8 @@ public static function fromArray( $missingFields = array_diff(self::EXPECTED_FIELDS, array_keys($data)); if ($missingFields) { throw new InvalidArgumentException(sprintf( - "Unable to create TaskMetaResult from invalid data. " . - "Missing fields: " . implode(',', $missingFields) + "Unable to create TaskMetaResult from invalid data. " + . "Missing fields: " . implode(',', $missingFields), )); } diff --git a/src/TaskSignature.php b/src/TaskSignature.php index 7f00195..6760f05 100644 --- a/src/TaskSignature.php +++ b/src/TaskSignature.php @@ -164,7 +164,7 @@ public function setRetries(?int $retries): self { /** * Countdown is a shortcut to set ETA by seconds into the future. - * See method TaskSignature::setEta() + * See method TaskSignature::setEta(). */ public function setCountdown(int $seconds): self { $self = clone $this; @@ -223,7 +223,8 @@ private function rawSetArgs(array $args): void { if (!array_is_list($args)) { throw new InvalidArgumentException( - "Args must be passed as an indexed array"); + "Args must be passed as an indexed array", + ); } $this->args = $args; @@ -247,7 +248,7 @@ private function rawSetRetries(?int $retries): void { /** * Countdown is a shortcut to set ETA by seconds into the future. - * See method TaskSignature::setEta() + * See method TaskSignature::setEta(). */ private function rawSetCountdown(int $seconds): void { @@ -292,7 +293,8 @@ protected static function ensureAtomDatetime($time): string { if (!strtotime($time)) { throw new InvalidArgumentException(sprintf( - "Cannot convert '%s' to datetime", $time + "Cannot convert '%s' to datetime", + $time, )); } @@ -305,7 +307,8 @@ protected static function ensureAtomDatetime($time): string { } throw new InvalidArgumentException(sprintf( - "Cannot convert '%s' to datetime", (string) $time, + "Cannot convert '%s' to datetime", + (string) $time, )); } diff --git a/tests/suite/AsyncResult.phpt b/tests/suite/AsyncResult.phpt index 4955dc1..66aa2ff 100644 --- a/tests/suite/AsyncResult.phpt +++ b/tests/suite/AsyncResult.phpt @@ -29,7 +29,7 @@ class TempBackend implements IResultBackend { return TaskMetaResult::fromArray( $taskId, - $this->storage[$taskId] ?? [] + $this->storage[$taskId] ?? [], ); } @@ -38,7 +38,7 @@ class TempBackend implements IResultBackend { string $taskId, $result, string $state, - ?string $traceback = null + ?string $traceback = null, ): void { self::$callCounter[__METHOD__]++; @@ -63,7 +63,7 @@ class TempBackend implements IResultBackend { } -$backend = new TempBackend; +$backend = new TempBackend(); // // Test getting a result from non-existing task ID. @@ -91,7 +91,7 @@ const TASK_RESULT = 'whatever result 🌭'; $backend->storeResult( TASK_ID, TASK_RESULT, - TASK_STATE + TASK_STATE, ); // @@ -137,7 +137,7 @@ Assert::noError(function() use ($result) { Assert::true( $backend::$callCounter['TempBackend::getTaskMetaResult'] > $called, - 'Unserialized AsyncResult with a non-ready state still fetches task meta info.' + 'Unserialized AsyncResult with a non-ready state still fetches task meta info.', ); // AsyncResult must not have an empty task ID. diff --git a/tests/suite/Control.Revoke.phpt b/tests/suite/Control.Revoke.phpt index 5ccda7d..4d4015f 100644 --- a/tests/suite/Control.Revoke.phpt +++ b/tests/suite/Control.Revoke.phpt @@ -13,7 +13,7 @@ use Smuuf\CeleryForPhp\Interfaces\IResultBackend; require __DIR__ . '/../bootstrap.php'; -$fakeBroker = new class implements IBroker { +$fakeBroker = new class() implements IBroker { private $last = []; @@ -33,7 +33,7 @@ $fakeBroker = new class implements IBroker { }; -$fakeResultBackend = new class implements IResultBackend { +$fakeResultBackend = new class() implements IResultBackend { public function getTaskMetaResult(string $taskId): TaskMetaResult { return new TaskMetaResult('meh'); diff --git a/tests/suite/Integration/RealTask.task.justWait.revoke.phpt b/tests/suite/Integration/RealTask.task.justWait.revoke.phpt index 666cfdd..7496f14 100644 --- a/tests/suite/Integration/RealTask.task.justWait.revoke.phpt +++ b/tests/suite/Integration/RealTask.task.justWait.revoke.phpt @@ -56,7 +56,7 @@ Assert::same(State::PENDING, $asyncResult->getState(), "A running task is PENDIN // Wait for result. $result = $asyncResult->get(); Assert::same(State::SUCCESS, $asyncResult->getState(), "State is a SUCCESS"); - Assert::same('YAY', $result, "Even revoked (without termination) task finished with a result"); +Assert::same('YAY', $result, "Even revoked (without termination) task finished with a result"); // // Just revoke. (with track_started=True) @@ -75,7 +75,7 @@ Assert::same(State::STARTED, $asyncResult->getState(), "A running task is STARTE // Wait for result. $result = $asyncResult->get(); Assert::same(State::SUCCESS, $asyncResult->getState(), "State is a SUCCESS"); - Assert::same('YAY_tracked_start', $result, "Even revoked (without termination) task finished with a result"); +Assert::same('YAY_tracked_start', $result, "Even revoked (without termination) task finished with a result"); // // Revoke + terminate (without track_started=True) diff --git a/tests/suite/Messaging.MessageBuilder.phpt b/tests/suite/Messaging.MessageBuilder.phpt index db3b162..edbd1c9 100644 --- a/tests/suite/Messaging.MessageBuilder.phpt +++ b/tests/suite/Messaging.MessageBuilder.phpt @@ -16,7 +16,7 @@ $sig = (new TaskSignature('celery_for_php.tasks.tests.some_task_name')) ->setQueue('some_very_queue') ->setCountdown(120) ->setExpiration('+2 hours') - ->setArgs([1,2,3]) + ->setArgs([1, 2, 3]) ->setKwargs(['arg_1' => 'hello', 'arg_2' => 'there']) ->setRetries(10) ->setTimeLimit(null, 3600); @@ -36,4 +36,3 @@ Assert::exception( InvalidArgumentException::class, 'Cannot format task message as unknown version 99987654', ); - diff --git a/tests/suite/Producer.phpt b/tests/suite/Producer.phpt index 1aead14..e39bf00 100644 --- a/tests/suite/Producer.phpt +++ b/tests/suite/Producer.phpt @@ -13,7 +13,7 @@ use Smuuf\CeleryForPhp\TaskSignature; require __DIR__ . '/../bootstrap.php'; -$fakeBroker = new class implements IBroker { +$fakeBroker = new class() implements IBroker { private $last = []; diff --git a/tests/suite/StrictObject.phpt b/tests/suite/StrictObject.phpt index fc142d1..00dedcd 100644 --- a/tests/suite/StrictObject.phpt +++ b/tests/suite/StrictObject.phpt @@ -5,7 +5,7 @@ use Tester\Assert; require __DIR__ . '/../bootstrap.php'; -$o = new class { +$o = new class() { use StrictObject; diff --git a/tests/suite/TaskMetaResult.phpt b/tests/suite/TaskMetaResult.phpt index 850b6e6..a110007 100644 --- a/tests/suite/TaskMetaResult.phpt +++ b/tests/suite/TaskMetaResult.phpt @@ -4,7 +4,7 @@ use Smuuf\CeleryForPhp\Exc\InvalidArgumentException; use Tester\Assert; use Smuuf\CeleryForPhp\State; -use Smuuf\CeleryForPhp\TaskMetaResult as TaskMetaResult; +use Smuuf\CeleryForPhp\TaskMetaResult; require __DIR__ . '/../bootstrap.php'; @@ -33,7 +33,7 @@ foreach ($empties as $tm) { $tm = new TaskMetaResult( TASK_ID, State::STARTED, - ['pid' => 123456, 'hostname' => 'some_machine'] + ['pid' => 123456, 'hostname' => 'some_machine'], ); Assert::same(TASK_ID, $tm->getTaskId()); Assert::same(State::STARTED, $tm->getState());