Completed
Push — master ( f8d577...6d4239 )
by Freek
18s queued 11s
created

EloquentSnapshot   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 22
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toSnapshot() 0 4 1
A scopeUuid() 0 4 1
1
<?php
2
3
namespace Spatie\EventSourcing\Snapshots;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use Illuminate\Database\Eloquent\Model;
7
8
class EloquentSnapshot extends Model
9
{
10
    public $guarded = [];
11
12
    public $timestamps = false;
13
14
    protected $table = 'snapshots';
15
16
    public $casts = [
17
        'state' => 'array',
18
    ];
19
20
    public function toSnapshot(): Snapshot
21
    {
22
        return new Snapshot($this->aggregate_uuid, $this->aggregate_version, $this->state);
23
    }
24
25
    public function scopeUuid(Builder $query, string $uuid): void
26
    {
27
        $query->where('aggregate_uuid', $uuid);
28
    }
29
}
30