UsesRivetsTableTrait::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace Luminark\Rivet\Traits;
4
5
use Luminark\Rivet\Models\Scopes\RivetTypeScope;
6
7
trait UsesRivetsTableTrait
8
{
9
    public static function boot()
10
    {
11
        parent::boot();
12
13
        static::addGlobalScope(new RivetTypeScope(static::getType()));
14
        static::saving(function ($model) {
15
            $model->type = $model::getType();
16
        });
17
    }
18
19
    public function getTable()
20
    {
21
        return 'rivets';
22
    }
23
24
    public static function getMorphToSortableManyOtherKey()
25
    {
26
        return 'rivet_id';
27
    }
28
29
    protected static function getType()
30
    {
31
        return static::class;
32
    }
33
}
34