Passed
Pull Request — master (#93)
by Gombos
06:23 queued 02:01
created

HasSettings::__call()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 7
ccs 0
cts 0
cp 0
rs 10
cc 4
nc 3
nop 2
crap 20
1
<?php
2
3
namespace Glorand\Model\Settings\Traits;
4
5
use Glorand\Model\Settings\Contracts\SettingsManagerContract;
6
use Illuminate\Support\Arr;
7
8
trait HasSettings
9
{
10 195
    public function getDefaultSettings(): array
11
    {
12 195
        if (property_exists($this, 'defaultSettings')
13 195
            && is_array($this->defaultSettings)) {
14 189
            return Arr::wrap($this->defaultSettings);
15 6
        } 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

15
        } 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

15
        } elseif (($defaultSettings = config('model_settings.defaultSettings.' . $this->/** @scrutinizer ignore-call */ getTable()))
Loading history...
16 6
            && is_array($defaultSettings)) {
17 3
            return Arr::wrap($defaultSettings);
18
        }
19 6
20
        return [];
21
    }
22
23
    public function __call($name, $args)
24
    {
25
        if (isset($this->invokeSettingsBy) && $name === $this->invokeSettingsBy) {
26
            return $this->settings();
27
        }
28
29
        return is_callable(['parent', '__call']) ? parent::__call($name, $args) : null;
30
    }
31
32
    abstract public function getSettingsValue(): array;
33
34
    abstract public function settings(): SettingsManagerContract;
35
}
36