Setting   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 18
c 2
b 0
f 0
dl 0
loc 54
ccs 10
cts 10
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTable() 0 7 2
A getCastType() 0 7 2
A model() 0 3 1
1
<?php
2
3
namespace Bavix\Settings\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Relations\MorphTo;
7
8
/**
9
 * Class Setting
10
 * @package Bavix\Settings\Models
11
 * @property string $key
12
 * @property string $cast
13
 * @property mixed $value
14
 */
15
class Setting extends Model
16
{
17
18
    /**
19
     * @var array
20
     */
21
    protected $fillable = [
22
        'model_type',
23
        'model_id',
24
        'key',
25
        'cast',
26
        'value',
27
    ];
28
29
    /**
30
     * @var array
31
     */
32
    protected $casts = [
33
        'key' => 'string',
34
        'cast' => 'string',
35
        'value' => 'custom',
36
    ];
37
38
    /**
39
     * @return \Illuminate\Config\Repository|mixed|string
40
     */
41 35
    public function getTable()
42
    {
43 35
        if (!$this->table) {
44 35
            $this->table = config('settings.table');
45
        }
46
47 35
        return parent::getTable();
48
    }
49
50
    /**
51
     * @return MorphTo
52
     */
53 10
    public function model(): MorphTo
54
    {
55 10
        return $this->morphTo();
56
    }
57
58
    /**
59
     * @param string $key
60
     * @return string
61
     */
62 35
    protected function getCastType($key): string
63
    {
64 35
        if ($key === 'value') {
65 35
            return $this->cast ?? 'string';
66
        }
67
68 35
        return parent::getCastType($key);
69
    }
70
71
}
72