HasSchemalessTable   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 26
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTable() 0 3 1
A getFillable() 0 8 1
A bootHasSchemalessTable() 0 9 3
1
<?php
2
3
namespace PrismX\Schemaless\Traits;
4
5
use Illuminate\Database\Eloquent\Model;
6
use PrismX\Schemaless\Support\DocumentScope;
7
8
trait HasSchemalessTable
9
{
10
    public static function bootHasSchemalessTable()
11
    {
12
        static::saving(function (Model &$model) {
13
            $model->model = $model->model ?: get_class($model);
14
            $model->locale = $model->locale ?: app()->getLocale();
0 ignored issues
show
introduced by
The method getLocale() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

14
            $model->locale = $model->locale ?: app()->/** @scrutinizer ignore-call */ getLocale();
Loading history...
15
        });
16
17
        // limit query of this model to its type
18
        static::addGlobalScope(new DocumentScope());
19
    }
20
21
    public function getTable()
22
    {
23
        return '_documents';
24
    }
25
26
    public function getFillable()
27
    {
28
        return array_merge(
29
            parent::getFillable(),
30
            [
31
                'model',
32
                'locale',
33
                'collection',
34
            ]
35
        );
36
    }
37
}
38