HasSettings   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
eloc 14
c 1
b 0
f 0
dl 0
loc 36
ccs 6
cts 6
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getRules() 0 7 3
A __call() 0 7 4
A getDefaultSettings() 0 11 5
1
<?php
2
3
namespace Glorand\Model\Settings\Traits;
4
5
use Glorand\Model\Settings\Contracts\SettingsManagerContract;
6
use Illuminate\Support\Arr;
7
8
/**
9
 * @property array $settingsRules
10 195
 * @property array $defaultSettings
11
 * @SuppressWarnings(PHPMD.StaticAccess)
12 195
 */
13 195
trait HasSettings
14 189
{
15 6
    public function getRules(): array
16 6
    {
17 3
        if (property_exists($this, 'settingsRules') && is_array($this->settingsRules)) {
18
            return $this->settingsRules;
19 6
        }
20
21
        return [];
22
    }
23
24
    public function getDefaultSettings(): array
25
    {
26
        if (property_exists($this, 'defaultSettings')
27
            && is_array($this->defaultSettings)) {
28
            return Arr::wrap($this->defaultSettings);
29
        } elseif (($defaultSettings = config('model_settings.defaultSettings.' . $this->getTable()))
0 ignored issues
show
Bug introduced by
Are you sure $this->getTable() of type Glorand\Model\Settings\C...agerContract|mixed|null can be used in concatenation? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

29
        } elseif (($defaultSettings = config('model_settings.defaultSettings.' . /** @scrutinizer ignore-type */ $this->getTable()))
Loading history...
Bug introduced by
The method getTable() does not exist on Glorand\Model\Settings\Traits\HasSettings. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
        } elseif (($defaultSettings = config('model_settings.defaultSettings.' . $this->/** @scrutinizer ignore-call */ getTable()))
Loading history...
30
            && is_array($defaultSettings)) {
31
            return Arr::wrap($defaultSettings);
32
        }
33
34
        return [];
35
    }
36
37
    public function __call($name, $args)
38
    {
39
        if (isset($this->invokeSettingsBy) && $name === $this->invokeSettingsBy) {
40
            return $this->settings();
41
        }
42
43
        return is_callable(['parent', '__call']) ? parent::__call($name, $args) : null;
44
    }
45
46
    abstract public function getSettingsValue(): array;
47
48
    abstract public function settings(): SettingsManagerContract;
49
}
50