Completed
Push — master ( a0d1c0...57787d )
by Freek
01:36
created

ProjectsEvents   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 29
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hasReceivedAllPriorEvents() 0 4 1
A rememberReceivedEvent() 0 4 1
A hasReceivedAllEvents() 0 4 1
A getName() 0 4 1
A getStatus() 0 4 1
1
<?php
2
3
namespace Spatie\EventProjector\Projectors;
4
5
use Spatie\EventProjector\Models\ProjectorStatus;
6
use Spatie\EventProjector\Models\StoredEvent;
7
8
trait ProjectsEvents
9
{
10
    public function hasReceivedAllPriorEvents(StoredEvent $storedEvent): bool
11
    {
12
        return $storedEvent->id === $this->getStatus()->last_processed_event_id + 1;
13
    }
14
15
    public function rememberReceivedEvent(StoredEvent $storedEvent)
16
    {
17
        $this->getStatus()->rememberLastProcessedEvent($storedEvent);
18
    }
19
20
    public function hasReceivedAllEvents(): bool
21
    {
22
        return $this->getStatus()->last_processed_event_id === StoredEvent::getMaxId();
23
    }
24
25
    public function getName(): string
26
    {
27
        return get_class($this);
28
    }
29
30
    protected function getStatus(): ProjectorStatus
31
    {
32
        return ProjectorStatus::getForProjector($this);
33
    }
34
35
36
}