Completed
Pull Request — master (#48)
by Rias
01:18
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\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 scopeUuid(Builder $query, string $uuid): void
28
    {
29
        $query->where('aggregate_uuid', $uuid);
30
    }
31
}
32