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

HasSettingsTable::settings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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