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

HasSettings   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 11
c 1
b 0
f 0
dl 0
loc 27
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultSettings() 0 11 5
A __call() 0 7 4
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