Passed
Push — master ( b6f366...fc6f44 )
by Karel
15:03
created

Module   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 20
c 1
b 0
f 1
dl 0
loc 52
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSetting() 0 4 2
A resolveSetting() 0 13 3
A getSettingsAttribute() 0 11 3
1
<?php
2
3
namespace Chuckbe\Chuckcms\Models;
4
5
use ChuckSite;
0 ignored issues
show
Bug introduced by
The type ChuckSite was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
7
use Eloquent;
8
9
class Module extends Eloquent
10
{
11
    /**
12
     * The attributes that are mass assignable.
13
     *
14
     * @var array
15
     */
16
    protected $fillable = [
17
        'name', 'slug', 'hintpath', 'path', 'type', 'version', 'author', 'json'
18
    ];
19
20
    /**
21
     * The attributes that are castable.
22
     *
23
     * @var array
24
     */
25
    protected $casts = [
26
        'json' => 'array',
27
    ];
28
29
    public function getSettingsAttribute()
30
    {
31
        if(!array_key_exists('admin', $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...
32
            return array();
33
        }
34
35
        if(!array_key_exists('settings', $this->json['admin'])) {
36
            return array();
37
        }
38
39
        return $this->json['admin']['settings'];
40
    }
41
42
    public function getSetting(string $string)
43
    {
44
        $setting = $this->resolveSetting($string);
45
        return $setting ? $setting : null;
46
    }
47
48
    private function resolveSetting($var)
49
    {
50
        $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...
51
        $split = explode('.', $var);
52
        foreach ($split as $value) {
53
            if (array_key_exists($value, $setting)) {
54
                $setting = $setting[$value];
55
            } else {
56
                return null;
57
            }
58
        }
59
60
        return $setting;
61
    }
62
}