1 | <?php |
||
27 | class CouchbaseQueue extends DatabaseQueue |
||
28 | { |
||
29 | /** |
||
30 | * The couchbase bucket that holds the jobs. |
||
31 | * |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $table; |
||
35 | |||
36 | /** @var CouchbaseConnection */ |
||
37 | protected $database; |
||
38 | |||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | */ |
||
42 | 2 | public function pop($queue = null) |
|
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | 2 | protected function marshalJob($queue, $job) |
|
63 | |||
64 | /** |
||
65 | * {@inheritdoc} |
||
66 | */ |
||
67 | 2 | protected function getNextAvailableJob($queue) |
|
80 | |||
81 | /** |
||
82 | * {@inheritdoc} |
||
83 | */ |
||
84 | 2 | protected function markJobAsReserved($job) |
|
97 | |||
98 | /** |
||
99 | * {@inheritdoc} |
||
100 | */ |
||
101 | 2 | public function bulk($jobs, $data = '', $queue = null) |
|
107 | |||
108 | /** |
||
109 | * {@inheritdoc} |
||
110 | */ |
||
111 | 2 | public function deleteReserved($queue, $id) |
|
115 | |||
116 | /** |
||
117 | * {@inheritdoc} |
||
118 | */ |
||
119 | 2 | protected function pushToDatabase($queue, $payload, $delay = 0, $attempts = 0) |
|
134 | |||
135 | /** |
||
136 | * generate increment key |
||
137 | * |
||
138 | * @param int $initial |
||
139 | * |
||
140 | * @return int |
||
141 | */ |
||
142 | 2 | protected function incrementKey($initial = 1) |
|
149 | |||
150 | /** |
||
151 | * @param array $attributes |
||
152 | * |
||
153 | * @return string |
||
154 | */ |
||
155 | 2 | protected function uniqueKey(array $attributes): string |
|
161 | |||
162 | /** |
||
163 | * @return string |
||
164 | */ |
||
165 | 2 | protected function identifier(): string |
|
169 | } |
||
170 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.