Module   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
eloc 22
c 3
b 1
f 1
dl 0
loc 57
rs 10
wmc 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSetting() 0 5 2
A resolveSetting() 0 13 3
A getSettingsAttribute() 0 15 4
1
<?php
2
3
namespace Chuckbe\Chuckcms\Models;
4
5
use Eloquent;
6
7
class Module extends Eloquent
8
{
9
    /**
10
     * The attributes that are mass assignable.
11
     *
12
     * @var array
13
     */
14
    protected $fillable = [
15
        'name', 'slug', 'hintpath', 'path', 'type', 'version', 'author', 'json',
16
    ];
17
18
    /**
19
     * The attributes that are castable.
20
     *
21
     * @var array
22
     */
23
    protected $casts = [
24
        'json' => 'array',
25
    ];
26
27
    public function getSettingsAttribute()
28
    {
29
        if (array_key_exists('settings', $this->json)) {
0 ignored issues
show
Bug Best Practice introduced by
The property json does not exist on Chuckbe\Chuckcms\Models\Module. Since you implemented __get, consider adding a @property annotation.
Loading history...
30
            return $this->json['settings'];
31
        }
32
33
        if (!array_key_exists('admin', $this->json)) {
34
            return [];
35
        }
36
37
        if (!array_key_exists('settings', $this->json['admin'])) {
38
            return [];
39
        }
40
41
        return $this->json['admin']['settings'];
42
    }
43
44
    public function getSetting(string $string)
45
    {
46
        $setting = $this->resolveSetting($string);
47
48
        return !is_null($setting) ? $setting : null;
49
    }
50
51
    private function resolveSetting($var)
52
    {
53
        $setting = $this->settings;
0 ignored issues
show
Bug Best Practice introduced by
The property settings does not exist on Chuckbe\Chuckcms\Models\Module. Since you implemented __get, consider adding a @property annotation.
Loading history...
54
        $split = explode('.', $var);
55
        foreach ($split as $value) {
56
            if (array_key_exists($value, $setting)) {
57
                $setting = $setting[$value];
58
            } else {
59
                return null;
60
            }
61
        }
62
63
        return $setting;
64
    }
65
}
66