HasOriginalModel::registerOriginModel()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.1755

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 8
nc 6
nop 1
dl 0
loc 16
ccs 7
cts 9
cp 0.7778
crap 4.1755
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace NovaFlexibleContent\Nova\Fields\TraitsForFlexible;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
/**
8
 * Hmm, I can't find place where this original model really useful.
9
 * We can use resolver for all functions, also data keeper can be not really model, but other class.
10
 * So I believe in future this functionality should be removed at all.
11
 * If you know place where this code required please write to me [email protected].
12
 *
13
 * @deprecated
14
 */
15
trait HasOriginalModel
16
{
17
    /**
18
     * @deprecated
19
     */
20
    public static Model|null $model;
21
22
    /**
23
     * Registers a reference to the origin model for nested & contained fields.
24
     *
25
     * @deprecated
26
     */
27 13
    protected function registerOriginModel($model): static
28
    {
29
        /** @psalm-suppress UndefinedClass */
30 13
        $isPageTemplate = is_a($model, "\Whitecube\NovaPage\Pages\Template");
31 13
        if (is_a($model, \Laravel\Nova\Resource::class)) {
32
            $model = $model->model();
33 13
        } elseif ($isPageTemplate) {
34
            /** @psalm-suppress UndefinedClass */
35
            $model = $model->getOriginal();
36
        }
37
38 13
        if (is_a($model, Model::class)) {
39 13
            static::$model = $model;
40
        }
41
42 13
        return $this;
43
    }
44
45
    /**
46
     * Return the previously registered origin model.
47
     *
48
     * @deprecated
49
     */
50
    public static function getOriginModel(): ?Model
51
    {
52
        return static::$model;
53
    }
54
}
55