Passed
Push — master ( b3505b...30c0cd )
by Бабичев
02:51
created

Setting::getTable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
1
<?php
2
3
namespace Bavix\Settings\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Relations\MorphTo;
7
8
class Setting extends Model
9
{
10
11
    /**
12
     * @var array
13
     */
14
    protected $fillable = [
15
        'model_type',
16
        'model_id',
17
        'key',
18
        'cast',
19
        'value',
20
    ];
21
22
    /**
23
     * @var array
24
     */
25
    protected $casts = [
26
        'key' => 'string',
27
        'cast' => 'string',
28
        'value' => 'custom',
29
    ];
30
31
    /**
32
     * @return \Illuminate\Config\Repository|mixed|string
33
     */
34 4
    public function getTable()
35
    {
36 4
        if (!$this->table) {
37 4
            $this->table = config('settings.table');
38
        }
39
40 4
        return parent::getTable();
41
    }
42
43
    /**
44
     * @return MorphTo
45
     */
46 4
    public function model(): MorphTo
47
    {
48 4
        return $this->morphTo();
49
    }
50
51
    /**
52
     * @param string $key
53
     * @return string
54
     */
55 4
    protected function getCastType($key): string
56
    {
57 4
        if ($key === 'value') {
58 4
            return $this->cast ?? 'string';
0 ignored issues
show
Bug introduced by
The property cast does not exist on Bavix\Settings\Models\Setting. Did you mean casts?
Loading history...
59
        }
60
61 4
        return parent::getCastType($key);
62
    }
63
64
}
65