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

HasSettings::getRules()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
cc 3
nc 2
nop 0
crap 3
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