Passed
Push — master ( da797a...38c1ce )
by Gombos
03:26
created

HasSettingsTable   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 31
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A settings() 0 3 1
A getSettingsValue() 0 6 2
A modelSettings() 0 3 1
1
<?php
2
3
namespace Glorand\Model\Settings\Traits;
4
5
use Glorand\Model\Settings\Contracts\SettingsManagerContract;
6
use Glorand\Model\Settings\Managers\TableSettingsManager;
7
use Glorand\Model\Settings\Models\ModelSettings;
8
use Illuminate\Database\Eloquent\Relations\MorphOne;
9
10
/**
11
 * Trait HasSettingsTable
12
 * @package Glorand\Model\Settings\Traits
13
 * @property ModelSettings $modelSettings
14
 * @property array $settings
15
 * @method morphOne($model, $name)
16
 */
17
trait HasSettingsTable
18
{
19
    use HasSettings;
20
21
    /**
22
     * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract
23
     * @throws \Glorand\Model\Settings\Exceptions\ModelSettingsException
24
     */
25 7
    public function settings(): SettingsManagerContract
26
    {
27 7
        return new TableSettingsManager($this);
1 ignored issue
show
Bug introduced by
$this of type Glorand\Model\Settings\Traits\HasSettingsTable is incompatible with the type Illuminate\Database\Eloquent\Model expected by parameter $model of Glorand\Model\Settings\M...sManager::__construct(). ( Ignorable by Annotation )

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

27
        return new TableSettingsManager(/** @scrutinizer ignore-type */ $this);
Loading history...
28
    }
29
30
    /**
31
     * @return array
32
     */
33 7
    public function getSettingsValue(): array
34
    {
35 7
        if ($modelSettings = $this->modelSettings()->first()) {
36 6
            return $modelSettings->settings;
37
        } else {
38 5
            return [];
39
        }
40
    }
41
42
    /**
43
     * @return \Illuminate\Database\Eloquent\Relations\MorphOne
44
     */
45 7
    public function modelSettings(): MorphOne
46
    {
47 7
        return $this->morphOne(ModelSettings::class, 'model');
48
    }
49
}
50