Completed
Pull Request — master (#48)
by Rias
01:12
created

EloquentSnapshot::toSnapshot()   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 0
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
9
class EloquentSnapshot extends Model
10
{
11
    public $guarded = [];
12
13
    public $timestamps = false;
14
15
    protected $table = 'snapshots';
16
17
    public $casts = [
18
        'state' => 'array',
19
    ];
20
21
    public function toSnapshot(): Snapshot
22
    {
23
        return new Snapshot($this->aggregate_uuid, $this->aggregate_version, $this->state);
24
    }
25
26
    public function scopeUuid(Builder $query, string $uuid): void
27
    {
28
        $query->where('aggregate_uuid', $uuid);
29
    }
30
}
31