Passed
Push — master ( eccffb...20dfb0 )
by Gombos
04:08 queued 42s
created

HasSettings   A

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 7
cts 7
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 $settingRules
10 195
 * @property array $defaultSettings
11
 */
12 195
trait HasSettings
13 195
{
14 189
    public function getRules(): array
15 6
    {
16 6
        if (property_exists($this, 'settingsRules') && is_array($this->settingsRules)) {
17 3
            return $this->settingsRules;
18
        }
19 6
20
        return [];
21
    }
22
23
    public function getDefaultSettings(): array
24
    {
25
        if (property_exists($this, 'defaultSettings')
26
            && is_array($this->defaultSettings)) {
27
            return Arr::wrap($this->defaultSettings);
28
        } elseif (($defaultSettings = config('model_settings.defaultSettings.' . $this->getTable()))
0 ignored issues
show
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

28
        } elseif (($defaultSettings = config('model_settings.defaultSettings.' . $this->/** @scrutinizer ignore-call */ getTable()))
Loading history...
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

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