1 | <?php |
||
21 | class MongoQueue extends Queue |
||
22 | { |
||
23 | /** |
||
24 | * Job resolver |
||
25 | * |
||
26 | * @var JobResolverInterface |
||
27 | */ |
||
28 | protected $resolver; |
||
29 | |||
30 | /** |
||
31 | * The mongo connection instance. |
||
32 | * |
||
33 | * @var MongoDriverInterface |
||
34 | */ |
||
35 | protected $mongo; |
||
36 | |||
37 | /** |
||
38 | * The mongo collection that holds the jobs. |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $collection; |
||
43 | |||
44 | /** |
||
45 | * The name of the default queue. |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $queue = 'default'; |
||
50 | |||
51 | /** |
||
52 | * The expiration time of a job. |
||
53 | * |
||
54 | * @var int|null |
||
55 | */ |
||
56 | protected $expire = 60; |
||
57 | |||
58 | /** |
||
59 | * @var int |
||
60 | */ |
||
61 | protected $limit = 15; |
||
62 | |||
63 | /** |
||
64 | * Create a new mongo queue instance. |
||
65 | * |
||
66 | * @param MongoDriverInterface $mongo |
||
67 | * @param string $collection |
||
68 | * @param string $queue |
||
69 | * @param int $expire |
||
70 | * @param int $limit |
||
71 | */ |
||
72 | public function __construct( |
||
87 | |||
88 | /** |
||
89 | * Push a new job onto the queue. |
||
90 | * |
||
91 | * @param string $job |
||
92 | * @param mixed $data |
||
93 | * @param string $queue |
||
94 | * |
||
95 | * @return mixed |
||
96 | */ |
||
97 | public function push(string $job, array $data = [], ?string $queue = null) |
||
101 | |||
102 | /** |
||
103 | * Pop the next job off of the queue. |
||
104 | * |
||
105 | * @param string $queue |
||
106 | * |
||
107 | * @return null|JobContractInterface |
||
108 | */ |
||
109 | public function pop(?string $queue = null): ?JobContractInterface |
||
119 | |||
120 | /** |
||
121 | * Check if job exists in the queue. |
||
122 | * |
||
123 | * @param string $job |
||
124 | * @param array $data |
||
125 | * @param string|null $queue |
||
126 | * |
||
127 | * @return bool |
||
128 | */ |
||
129 | public function exists(string $job, array $data = [], ?string $queue = null): bool |
||
136 | |||
137 | /** |
||
138 | * Push a raw payload onto the queue. |
||
139 | * |
||
140 | * @param string $payload |
||
141 | * @param string|null $queue |
||
142 | * @param array $options |
||
143 | * |
||
144 | * @return mixed |
||
145 | */ |
||
146 | public function pushRaw(string $payload, ?string $queue = null, array $options = []) |
||
150 | |||
151 | /** |
||
152 | * Push a new job onto the queue after a delay. |
||
153 | * |
||
154 | * @param DateInterval|int $delay |
||
155 | * @param string $job |
||
156 | * @param array $data |
||
157 | * @param string $queue |
||
158 | * |
||
159 | * @return mixed |
||
160 | */ |
||
161 | public function later($delay, string $job, array $data = [], ?string $queue = null) |
||
165 | |||
166 | /** |
||
167 | * Push an array of jobs onto the queue. |
||
168 | * |
||
169 | * @param array $jobs |
||
170 | * @param mixed $data |
||
171 | * @param string $queue |
||
172 | * |
||
173 | * @return mixed |
||
174 | */ |
||
175 | public function bulk(array $jobs, array $data = [], ?string $queue = null) |
||
187 | |||
188 | /** |
||
189 | * Release a reserved job back onto the queue. |
||
190 | * |
||
191 | * @param Job $job |
||
192 | * @param DateInterval|int $delay |
||
193 | * |
||
194 | * @return mixed |
||
195 | */ |
||
196 | public function release(Job $job, $delay) |
||
200 | |||
201 | /** |
||
202 | * Get the next available job for the queue. |
||
203 | * |
||
204 | * @param $id |
||
205 | * |
||
206 | * @return null|JobContractInterface |
||
207 | */ |
||
208 | public function getJobById($id): ?JobContractInterface |
||
218 | |||
219 | /** |
||
220 | * Delete a reserved job from the queue. |
||
221 | * |
||
222 | * @param string $queue |
||
223 | * @param string $id |
||
224 | * |
||
225 | * @return bool |
||
226 | */ |
||
227 | public function deleteReserved(string $queue, $id): bool |
||
242 | |||
243 | /** |
||
244 | * Get the expiration time in seconds. |
||
245 | * |
||
246 | * @return int|null |
||
247 | */ |
||
248 | public function getExpire() |
||
252 | |||
253 | /** |
||
254 | * Set the expiration time in seconds. |
||
255 | * |
||
256 | * @param int $seconds |
||
257 | */ |
||
258 | public function setExpire(int $seconds) |
||
262 | |||
263 | /** |
||
264 | * Get the size of the queue. |
||
265 | * |
||
266 | * @param string $queue |
||
267 | * |
||
268 | * @return int |
||
269 | */ |
||
270 | public function size(?string $queue = null): int |
||
278 | |||
279 | /** |
||
280 | * Check if can run process depend on limits |
||
281 | * |
||
282 | * @param JobContractInterface $job |
||
283 | * |
||
284 | * @return bool |
||
285 | */ |
||
286 | public function canRunJob(JobContractInterface $job): bool |
||
293 | |||
294 | /** |
||
295 | * Mark the given job ID as reserved. |
||
296 | * |
||
297 | * @param JobContractInterface $job |
||
298 | */ |
||
299 | public function markJobAsReserved(JobContractInterface $job) |
||
312 | |||
313 | /** |
||
314 | * Push a raw payload to the mongo with a given delay. |
||
315 | * |
||
316 | * @param DateInterval|int $delay |
||
317 | * @param string|null $queue |
||
318 | * @param string $payload |
||
319 | * @param int $attempts |
||
320 | * |
||
321 | * @return mixed |
||
322 | */ |
||
323 | protected function pushToDatabase($delay, $queue, $payload, $attempts = 0) |
||
329 | |||
330 | /** |
||
331 | * Get the "available at" UNIX timestamp. |
||
332 | * |
||
333 | * @param DateInterval|int $delay |
||
334 | * |
||
335 | * @return int |
||
336 | */ |
||
337 | protected function getAvailableAt($delay = 0) |
||
343 | |||
344 | /** |
||
345 | * Get the queue or return the default. |
||
346 | * |
||
347 | * @param string|null $queue |
||
348 | * |
||
349 | * @return string |
||
350 | */ |
||
351 | protected function getQueue($queue) |
||
355 | |||
356 | /** |
||
357 | * Get the next available job for the queue. |
||
358 | * |
||
359 | * @param string|null $queue |
||
360 | * |
||
361 | * @return null|JobContractInterface |
||
362 | */ |
||
363 | protected function getNextAvailableJob($queue) |
||
378 | |||
379 | /** |
||
380 | * Create an array to insert for the given job. |
||
381 | * |
||
382 | * @param string|null $queue |
||
383 | * @param string $payload |
||
384 | * @param int $availableAt |
||
385 | * @param int $attempts |
||
386 | * |
||
387 | * @return array |
||
388 | */ |
||
389 | protected function buildDatabaseRecord($queue, $payload, $availableAt, $attempts = 0) |
||
401 | |||
402 | /** |
||
403 | * Get available jobs |
||
404 | * |
||
405 | * @return array |
||
406 | */ |
||
407 | protected function isAvailable() |
||
414 | |||
415 | /** |
||
416 | * Get reserved but expired by time jobs |
||
417 | * |
||
418 | * @return array |
||
419 | */ |
||
420 | protected function isReservedButExpired() |
||
426 | |||
427 | /** |
||
428 | * Get queue collection |
||
429 | * |
||
430 | * @return Collection Mongo collection instance |
||
431 | */ |
||
432 | protected function getCollection(): Collection |
||
436 | |||
437 | /** |
||
438 | * Build job from database record |
||
439 | * |
||
440 | * @param $data |
||
441 | * |
||
442 | * @return Job |
||
443 | */ |
||
444 | protected function buildJob($data): Job |
||
456 | } |
||
457 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.