HasSchemalessTable::getFillable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 10
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