|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Stu\Component\Event; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
|
6
|
|
|
use Doctrine\Common\Collections\Collection; |
|
7
|
|
|
use Doctrine\Common\Collections\Criteria; |
|
8
|
|
|
use Doctrine\Common\Collections\Order; |
|
9
|
|
|
use Override; |
|
|
|
|
|
|
10
|
|
|
use RuntimeException; |
|
11
|
|
|
use Stu\Orm\Entity\EventInterface; |
|
12
|
|
|
use Stu\Orm\Repository\EventRepositoryInterface; |
|
13
|
|
|
|
|
14
|
|
|
class EventQueue implements EventQueueInterface |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var null|ArrayCollection<int, EventInterface> */ |
|
17
|
|
|
private ?Collection $events = null; |
|
18
|
|
|
|
|
19
|
6 |
|
public function __construct(private EventRepositoryInterface $eventRepository) |
|
20
|
|
|
{ |
|
21
|
6 |
|
} |
|
22
|
|
|
|
|
23
|
3 |
|
#[Override] |
|
24
|
|
|
public function getSize(): int |
|
25
|
|
|
{ |
|
26
|
3 |
|
return $this->getEvents()->count(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
3 |
|
#[Override] |
|
30
|
|
|
public function getNextEvent(): EventInterface |
|
31
|
|
|
{ |
|
32
|
3 |
|
$next = $this->getEvents()->matching( |
|
|
|
|
|
|
33
|
3 |
|
Criteria::create() |
|
34
|
3 |
|
->orderBy([ |
|
35
|
3 |
|
'priority' => Order::Descending, |
|
36
|
3 |
|
'retries' => Order::Descending |
|
37
|
3 |
|
]) |
|
38
|
3 |
|
)->first(); |
|
39
|
|
|
|
|
40
|
3 |
|
if (!$next) { |
|
41
|
1 |
|
throw new RuntimeException('isEmpty should be called first'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
2 |
|
return $next; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
1 |
|
#[Override] |
|
48
|
|
|
public function addEvent(EventInterface $event): void |
|
49
|
|
|
{ |
|
50
|
1 |
|
$this->getEvents()->add($event); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
1 |
|
#[Override] |
|
54
|
|
|
public function removeEvent(EventInterface $event): void |
|
55
|
|
|
{ |
|
56
|
1 |
|
$this->getEvents()->removeElement($event); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function clear(): void |
|
60
|
|
|
{ |
|
61
|
|
|
$this->getEvents()->clear(); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** @return ArrayCollection<int, EventInterface> */ |
|
65
|
6 |
|
private function getEvents(): Collection |
|
66
|
|
|
{ |
|
67
|
6 |
|
if ($this->events === null) { |
|
68
|
6 |
|
$this->events = $this->eventRepository->getEventsByPriority(); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
6 |
|
return $this->events; |
|
|
|
|
|
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths