Completed
Push — master ( 676adf...d90d0b )
by Freek
01:27
created

ProjectsEvents::getName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace Spatie\EventProjector\Projectors;
4
5
use Carbon\Carbon;
6
use Spatie\EventProjector\Models\StoredEvent;
7
use Spatie\EventProjector\Models\ProjectorStatus;
8
9
trait ProjectsEvents
10
{
11
    public function hasReceivedAllPriorEvents(StoredEvent $storedEvent): bool
12
    {
13
        return $storedEvent->id === $this->getStatus()->last_processed_event_id + 1;
14
    }
15
16
    public function rememberReceivedEvent(StoredEvent $storedEvent)
17
    {
18
        $this->getStatus()->rememberLastProcessedEvent($storedEvent);
19
    }
20
21
    public function hasReceivedAllEvents(): bool
22
    {
23
        return (int)$this->getStatus()->last_processed_event_id === StoredEvent::getMaxId();
24
    }
25
26
    public function getName(): string
27
    {
28
        if (isset($this->name)) {
29
            return $this->name;
0 ignored issues
show
Bug introduced by
The property name does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
30
        }
31
32
        return get_class($this);
33
    }
34
35
    public function getLastProcessedEventId(): int
36
    {
37
        return $this->getStatus()->last_processed_event_id;
38
    }
39
40
    public function lastEventProcessedAt(): Carbon
41
    {
42
        return $this->getStatus()->updated_at;
43
    }
44
45
    public function resetStatus()
46
    {
47
        $this->getStatus()->delete();
48
    }
49
50
    protected function getStatus(): ProjectorStatus
51
    {
52
        return ProjectorStatus::getForProjector($this);
53
    }
54
55
56
}
57