Completed
Push — master ( c1932e...0de009 )
by Freek
27s queued 11s
created

EloquentStoredEvent::scopeStartingFrom()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Spatie\EventProjector\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Builder;
7
use Spatie\EventProjector\ShouldBeStored;
8
9
class EloquentStoredEvent extends Model
10
{
11
    public $guarded = [];
12
13
    public $timestamps = false;
14
15
    protected $table = 'stored_events';
16
17
    public $casts = [
18
        'event_properties' => 'array',
19
        'meta_data' => 'array',
20
    ];
21
22
    public function toStoredEvent(): StoredEvent
23
    {
24
        return new StoredEvent([
25
            'id' => $this->id,
26
            'event_properties' => $this->event_properties,
27
            'aggregate_uuid' => $this->aggregate_uuid,
28
            'event_class' => $this->event_class,
29
            'meta_data' => $this->meta_data,
30
            'created_at' => $this->created_at,
31
        ]);
32
    }
33
34
    public function getEventAttribute(): ShouldBeStored
35
    {
36
        return $this->toStoredEvent()->event;
37
    }
38
39
    public function scopeStartingFrom(Builder $query, int $storedEventId): void
40
    {
41
        $query->where('id', '>=', $storedEventId);
42
    }
43
44
    public function scopeUuid(Builder $query, string $uuid): void
45
    {
46
        $query->where('aggregate_uuid', $uuid);
47
    }
48
}
49