Skip to content

Commit

Permalink
Fixed code style stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
smuuf committed Nov 4, 2023
1 parent bbc318f commit 7a4d520
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 47 deletions.
5 changes: 5 additions & 0 deletions bin/code-style.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=$?

Expand Down
3 changes: 1 addition & 2 deletions src/AsyncResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ 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.
* @param string $controlExchangeName
* 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,
Expand Down
4 changes: 1 addition & 3 deletions src/Exc/CeleryTimeoutException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

namespace Smuuf\CeleryForPhp\Exc;

class CeleryTimeoutException extends \RuntimeException implements ICeleryForPhpException {

}
class CeleryTimeoutException extends \RuntimeException implements ICeleryForPhpException {}
4 changes: 1 addition & 3 deletions src/Exc/ICeleryForPhpException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

namespace Smuuf\CeleryForPhp\Exc;

interface ICeleryForPhpException extends \Throwable {

}
interface ICeleryForPhpException extends \Throwable {}
4 changes: 1 addition & 3 deletions src/Exc/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

namespace Smuuf\CeleryForPhp\Exc;

class InvalidArgumentException extends \LogicException implements ICeleryForPhpException {

}
class InvalidArgumentException extends \LogicException implements ICeleryForPhpException {}
4 changes: 1 addition & 3 deletions src/Exc/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@

namespace Smuuf\CeleryForPhp\Exc;

class RuntimeException extends \RuntimeException implements ICeleryForPhpException {

}
class RuntimeException extends \RuntimeException implements ICeleryForPhpException {}
6 changes: 3 additions & 3 deletions src/Helpers/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/Messaging/MessageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/TaskMetaResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
));
}

Expand Down
13 changes: 8 additions & 5 deletions src/TaskSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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,
));
}

Expand All @@ -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,
));

}
Expand Down
10 changes: 5 additions & 5 deletions tests/suite/AsyncResult.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TempBackend implements IResultBackend {

return TaskMetaResult::fromArray(
$taskId,
$this->storage[$taskId] ?? []
$this->storage[$taskId] ?? [],
);

}
Expand All @@ -38,7 +38,7 @@ class TempBackend implements IResultBackend {
string $taskId,
$result,
string $state,
?string $traceback = null
?string $traceback = null,
): void {

self::$callCounter[__METHOD__]++;
Expand All @@ -63,7 +63,7 @@ class TempBackend implements IResultBackend {

}

$backend = new TempBackend;
$backend = new TempBackend();

//
// Test getting a result from non-existing task ID.
Expand Down Expand Up @@ -91,7 +91,7 @@ const TASK_RESULT = 'whatever result 🌭';
$backend->storeResult(
TASK_ID,
TASK_RESULT,
TASK_STATE
TASK_STATE,
);

//
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions tests/suite/Control.Revoke.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand All @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions tests/suite/Integration/RealTask.task.justWait.revoke.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions tests/suite/Messaging.MessageBuilder.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -36,4 +36,3 @@ Assert::exception(
InvalidArgumentException::class,
'Cannot format task message as unknown version 99987654',
);

2 changes: 1 addition & 1 deletion tests/suite/Producer.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use Smuuf\CeleryForPhp\TaskSignature;

require __DIR__ . '/../bootstrap.php';

$fakeBroker = new class implements IBroker {
$fakeBroker = new class() implements IBroker {

private $last = [];

Expand Down
2 changes: 1 addition & 1 deletion tests/suite/StrictObject.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use Tester\Assert;

require __DIR__ . '/../bootstrap.php';

$o = new class {
$o = new class() {

use StrictObject;

Expand Down
4 changes: 2 additions & 2 deletions tests/suite/TaskMetaResult.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 7a4d520

Please sign in to comment.