Completed
Pull Request — master (#48)
by Rias
61:09 queued 59:41
created

EloquentSnapshot::scopeUuid()   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\EventSourcing\Models;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Database\Eloquent\Model;
7
use Spatie\EventSourcing\Snapshot;
8
use Spatie\SchemalessAttributes\SchemalessAttributes;
9
10
class EloquentSnapshot extends Model
11
{
12
    public $guarded = [];
13
14
    public $timestamps = false;
15
16
    protected $table = 'snapshots';
17
18
    public $casts = [
19
        'state' => 'array',
20
    ];
21
22
    public function toSnapshot(): Snapshot
23
    {
24
        return new Snapshot($this->aggregate_uuid, $this->aggregate_version, $this->state);
25
    }
26
27
    public function getStateAttribute(): SchemalessAttributes
28
    {
29
        return SchemalessAttributes::createForModel($this, 'state');
30
    }
31
32
    public function scopeUuid(Builder $query, string $uuid): void
33
    {
34
        $query->where('aggregate_uuid', $uuid);
35
    }
36
}
37