Total Complexity | 12 |
Total Lines | 89 |
Duplicated Lines | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
7 | abstract class BaseTask |
||
8 | { |
||
9 | /** |
||
10 | * The number of seconds before the task should be delayed. |
||
11 | * @var int |
||
12 | */ |
||
13 | protected $delay = 0; |
||
14 | |||
15 | /** |
||
16 | * The number of tries. |
||
17 | * @var int |
||
18 | */ |
||
19 | protected $tries = 1; |
||
20 | |||
21 | /** |
||
22 | * Delay in seconds, null means no delay. |
||
23 | * @param int $delay |
||
24 | * @return $this |
||
25 | */ |
||
26 | public function delay($delay) |
||
27 | { |
||
28 | if ($delay < 0) { |
||
29 | throw new \InvalidArgumentException('The delay must be greater than or equal to 0'); |
||
30 | } |
||
31 | $this->delay = (int)$delay; |
||
32 | return $this; |
||
33 | } |
||
34 | |||
35 | /** |
||
36 | * Return the delay time. |
||
37 | * @return int |
||
38 | */ |
||
39 | public function getDelay() |
||
40 | { |
||
41 | return $this->delay; |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * Set the number of tries. |
||
46 | * @param int $tries |
||
47 | * @return $this |
||
48 | */ |
||
49 | public function setTries($tries) |
||
50 | { |
||
51 | if ($tries < 1) { |
||
52 | throw new \InvalidArgumentException('The number of attempts must be greater than or equal to 1'); |
||
53 | } |
||
54 | $this->tries = (int)$tries; |
||
55 | return $this; |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * Get the number of tries. |
||
60 | * @return int |
||
61 | */ |
||
62 | public function getTries() |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * Deliver a task |
||
69 | * @param mixed $task The task object |
||
70 | * @return bool |
||
71 | */ |
||
72 | protected function task($task) |
||
96 | } |
||
97 | } |