Skip to content

Commit e05357f

Browse files
committed
TASK: Set types in interface methods
1 parent acb68e9 commit e05357f

5 files changed

Lines changed: 51 additions & 49 deletions

File tree

Classes/Job/JobInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ interface JobInterface
2727
*
2828
* @param QueueInterface $queue
2929
* @param Message $message The original message
30-
* @return boolean TRUE if the job was executed successfully and the message should be finished
30+
* @return bool TRUE if the job was executed successfully and the message should be finished
3131
*/
32-
public function execute(QueueInterface $queue, Message $message);
32+
public function execute(QueueInterface $queue, Message $message): bool;
3333

3434
/**
3535
* Get a readable label for the job
3636
*
3737
* @return string A label for the job
3838
*/
39-
public function getLabel();
39+
public function getLabel(): string;
4040
}

Classes/Queue/FakeQueue.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function __construct($name, array $options = [])
6060
/**
6161
* @inheritdoc
6262
*/
63-
public function setUp()
63+
public function setUp(): void
6464
{
6565
// The FakeQueue does not require any setup but we use it to verify the options
6666
if ($this->async && !method_exists(Scripts::class, 'executeCommandAsync')) {
@@ -71,15 +71,15 @@ public function setUp()
7171
/**
7272
* @inheritdoc
7373
*/
74-
public function getName()
74+
public function getName(): string
7575
{
7676
return $this->name;
7777
}
7878

7979
/**
8080
* @inheritdoc
8181
*/
82-
public function submit($payload, array $options = [])
82+
public function submit($payload, array $options = []): string
8383
{
8484
$messageId = Algorithms::generateUUID();
8585
$message = new Message($messageId, $payload);
@@ -98,47 +98,47 @@ public function submit($payload, array $options = [])
9898
/**
9999
* @inheritdoc
100100
*/
101-
public function waitAndTake($timeout = null)
101+
public function waitAndTake(int $timeout = null): Message
102102
{
103103
throw new \BadMethodCallException('The FakeQueue does not support reserving of messages.' . chr(10) . 'It is not required to use a worker for this queue as messages are handled immediately upon submission.', 1468425275);
104104
}
105105

106106
/**
107107
* @inheritdoc
108108
*/
109-
public function waitAndReserve($timeout = null)
109+
public function waitAndReserve(int $timeout = null): Message
110110
{
111111
throw new \BadMethodCallException('The FakeQueue does not support reserving of messages.' . chr(10) . 'It is not required to use a worker for this queue as messages are handled immediately upon submission.', 1468425280);
112112
}
113113

114114
/**
115115
* @inheritdoc
116116
*/
117-
public function release($messageId, array $options = [])
117+
public function release(string $messageId, array $options = []): void
118118
{
119119
throw new \BadMethodCallException('The FakeQueue does not support releasing of failed messages.' . chr(10) . 'The "maximumNumberOfReleases" setting should be removed or set to 0 for this queue!', 1468425285);
120120
}
121121

122122
/**
123123
* @inheritdoc
124124
*/
125-
public function abort($messageId)
125+
public function abort(string $messageId): void
126126
{
127127
// The FakeQueue does not support message abortion
128128
}
129129

130130
/**
131131
* @inheritdoc
132132
*/
133-
public function finish($messageId)
133+
public function finish(string $messageId): bool
134134
{
135135
// The FakeQueue does not support message finishing
136136
}
137137

138138
/**
139139
* @inheritdoc
140140
*/
141-
public function peek($limit = 1)
141+
public function peek(int $limit = 1): array
142142
{
143143
return [];
144144
}
@@ -170,7 +170,7 @@ public function countFailed(): int
170170
/**
171171
* @inheritdoc
172172
*/
173-
public function flush()
173+
public function flush(): void
174174
{
175175
// The FakeQueue does not support message flushing
176176
}

Classes/Queue/QueueInterface.php

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ interface QueueInterface
2121
/**
2222
* @return void
2323
*/
24-
public function setUp();
24+
public function setUp(): void;
2525

2626
/**
2727
* The unique name of this queue
2828
*
2929
* @return string
3030
*/
31-
public function getName();
31+
public function getName(): string;
3232

3333
/**
3434
* Submit a message to the queue
@@ -37,17 +37,17 @@ public function getName();
3737
* @param array $options Simple key/value array with options, supported options depend on the queue implementation
3838
* @return string The identifier of the message under which it was queued
3939
*/
40-
public function submit($payload, array $options = []);
40+
public function submit($payload, array $options = []): string;
4141

4242
/**
4343
* Wait for a message in the queue and remove the message from the queue for processing
4444
* If a non-null value was returned, the message was not queued. Otherwise a timeout
4545
* occurred and no message was available or received.
4646
*
47-
* @param integer $timeout
47+
* @param int $timeout
4848
* @return Message The received message or NULL if a timeout occurred
4949
*/
50-
public function waitAndTake($timeout = null);
50+
public function waitAndTake(?int $timeout = null): ?Message;
5151

5252
/**
5353
* Wait for a message in the queue and reserve the message for processing
@@ -57,10 +57,10 @@ public function waitAndTake($timeout = null);
5757
* If a non-null value was returned, the message was reserved. Otherwise a timeout
5858
* occurred and no message was available or received.
5959
*
60-
* @param integer $timeout
60+
* @param int $timeout
6161
* @return Message The received message or NULL if a timeout occurred
6262
*/
63-
public function waitAndReserve($timeout = null);
63+
public function waitAndReserve(?int $timeout = null): ?Message;
6464

6565
/**
6666
* Puts a reserved message back to the queue
@@ -69,15 +69,15 @@ public function waitAndReserve($timeout = null);
6969
* @param array $options Simple key/value array with options that can be interpreted by the concrete implementation (optional)
7070
* @return void
7171
*/
72-
public function release($messageId, array $options = []);
72+
public function release(string $messageId, array $options = []): void;
7373

7474
/**
7575
* Removes a message from the active queue and marks it failed (bury)
7676
*
7777
* @param string $messageId
7878
* @return void
7979
*/
80-
public function abort($messageId);
80+
public function abort(string $messageId): void;
8181

8282
/**
8383
* Mark a message as done
@@ -86,9 +86,9 @@ public function abort($messageId);
8686
* processed successfully.
8787
*
8888
* @param string $messageId
89-
* @return boolean TRUE if the message could be removed
89+
* @return bool TRUE if the message could be removed
9090
*/
91-
public function finish($messageId);
91+
public function finish(string $messageId): bool;
9292

9393
/**
9494
* Peek for messages
@@ -99,7 +99,7 @@ public function finish($messageId);
9999
* @param integer $limit
100100
* @return Message[] The messages up to the length of limit or an empty array if no messages are present currently
101101
*/
102-
public function peek($limit = 1);
102+
public function peek(int $limit = 1): array;
103103

104104
/**
105105
* Get a count of ready messages currently in the queue.
@@ -130,5 +130,5 @@ public function countFailed(): int;
130130
*
131131
* @return void
132132
*/
133-
public function flush();
133+
public function flush(): void;
134134
}

Tests/Unit/Fixtures/TestJob.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@ public function __construct($failNumberOfTimes = 0)
3333
$this->failNumberOfTimes = $failNumberOfTimes;
3434
}
3535

36-
3736
/**
3837
* Do nothing
3938
*
4039
* @param QueueInterface $queue
4140
* @param Message $message
42-
* @return boolean
41+
* @return bool
4342
*/
44-
public function execute(QueueInterface $queue, Message $message)
43+
public function execute(QueueInterface $queue, Message $message): bool
4544
{
4645
if ($this->failNumberOfTimes > $message->getNumberOfReleases()) {
4746
return false;
@@ -54,7 +53,7 @@ public function execute(QueueInterface $queue, Message $message)
5453
*
5554
* @return string A label for the job
5655
*/
57-
public function getLabel()
56+
public function getLabel(): string
5857
{
5958
return 'Test Job';
6059
}

0 commit comments

Comments
 (0)