Skip to content

Commit

Permalink
Merge pull request #10 from daniellienert/task/set-types
Browse files Browse the repository at this point in the history
TASK: Define types according to the interface
  • Loading branch information
daniellienert authored Jun 19, 2018
2 parents 97c8415 + 8392317 commit b01d776
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions Classes/Queue/RedisQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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()
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -192,6 +199,7 @@ public function peek($limit = 1)

/**
* @inheritdoc
* @throws JobQueueException
*/
public function countReady(): int
{
Expand All @@ -201,6 +209,7 @@ public function countReady(): int

/**
* @inheritdoc
* @throws JobQueueException
*/
public function countReserved(): int
{
Expand All @@ -210,6 +219,7 @@ public function countReserved(): int

/**
* @inheritdoc
* @throws JobQueueException
*/
public function countFailed(): int
{
Expand All @@ -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();
Expand All @@ -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;
Expand Down

0 comments on commit b01d776

Please sign in to comment.