From 839231730d352c99aa9e3039f28821e65b5dbc33 Mon Sep 17 00:00:00 2001 From: Daniel Lienert Date: Wed, 30 May 2018 10:29:25 +0200 Subject: [PATCH] TASK: Define types according to the interface --- Classes/Queue/RedisQueue.php | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/Classes/Queue/RedisQueue.php b/Classes/Queue/RedisQueue.php index 20785b0..b67a460 100644 --- a/Classes/Queue/RedisQueue.php +++ b/Classes/Queue/RedisQueue.php @@ -80,15 +80,16 @@ public function __construct($name, array $options = []) /** * @inheritdoc */ - public function getName() + public function getName(): string { return $this->name; } /** * @inheritdoc + * @throws JobQueueException */ - public function submit($payload, array $options = []) + public function submit($payload, array $options = []): string { $this->checkClientConnection(); $messageId = Algorithms::generateUUID(); @@ -103,8 +104,9 @@ public function submit($payload, array $options = []) /** * @inheritdoc + * @throws JobQueueException */ - public function waitAndTake($timeout = null) + public function waitAndTake(?int $timeout = null): ?Message { if ($timeout === null) { $timeout = $this->defaultTimeout; @@ -124,8 +126,9 @@ public function waitAndTake($timeout = null) /** * @inheritdoc + * @throws JobQueueException */ - public function waitAndReserve($timeout = null) + public function waitAndReserve(?int $timeout = null): ?Message { if ($timeout === null) { $timeout = $this->defaultTimeout; @@ -137,8 +140,9 @@ public function waitAndReserve($timeout = null) /** * @inheritdoc + * @throws JobQueueException */ - public function release($messageId, array $options = []) + public function release(string $messageId, array $options = []): void { $this->checkClientConnection(); $this->client->multi() @@ -150,8 +154,9 @@ public function release($messageId, array $options = []) /** * @inheritdoc + * @throws JobQueueException */ - public function abort($messageId) + public function abort(string $messageId): void { $this->checkClientConnection(); $numberOfRemoved = $this->client->lRem("queue:{$this->name}:processing", $messageId, 0); @@ -162,8 +167,9 @@ public function abort($messageId) /** * @inheritdoc + * @throws JobQueueException */ - public function finish($messageId) + public function finish(string $messageId): bool { $this->checkClientConnection(); $numberOfRemoved = $this->client->lRem("queue:{$this->name}:processing", $messageId, 0); @@ -174,8 +180,9 @@ public function finish($messageId) /** * @inheritdoc + * @throws JobQueueException */ - public function peek($limit = 1) + public function peek(int $limit = 1): array { $this->checkClientConnection(); $result = $this->client->lRange("queue:{$this->name}:messages", -($limit), -1); @@ -192,6 +199,7 @@ public function peek($limit = 1) /** * @inheritdoc + * @throws JobQueueException */ public function countReady(): int { @@ -201,6 +209,7 @@ public function countReady(): int /** * @inheritdoc + * @throws JobQueueException */ public function countReserved(): int { @@ -210,6 +219,7 @@ public function countReserved(): int /** * @inheritdoc + * @throws JobQueueException */ public function countFailed(): int { @@ -221,15 +231,16 @@ public function countFailed(): int * @return void * @throws JobQueueException */ - public function setUp() + public function setUp(): void { $this->checkClientConnection(); } /** * @inheritdoc + * @throws JobQueueException */ - public function flush() + public function flush(): void { $this->checkClientConnection(); $this->client->flushDB(); @@ -239,7 +250,7 @@ public function flush() * @param string $messageId * @return Message */ - protected function getMessageById($messageId) + protected function getMessageById(string $messageId): ?Message { if (!is_string($messageId)) { return null;