Passed
Pull Request — master (#1)
by Gombos
01:47
created

HasSettingsField::getSettingsAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
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\FieldSettingsManager;
7
8
/**
9
 * Trait HasSettingsField
10
 * @package Glorand\Model\Settings\Traits
11
 * @property array $settings
12
 */
13
trait HasSettingsField
14
{
15
    /**
16
     * @param string $path
17
     * @param null $default
1 ignored issue
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $default is correct as it would always require null to be passed?
Loading history...
18
     * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract
19
     */
20
    public function settings(string $path = null, $default = null): SettingsManagerContract
21
    {
22
        return $path ? $this->settings()->get($path, $default) : new FieldSettingsManager($this);
23
    }
24
25
    protected function getSettingsAttribute()
26
    {
27
        return json_decode($this->getAttributes()['settings'], true);
0 ignored issues
show
Bug introduced by
It seems like getAttributes() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

27
        return json_decode($this->/** @scrutinizer ignore-call */ getAttributes()['settings'], true);
Loading history...
28
    }
29
30
    public function setSettingsAttribute($settings)
31
    {
32
        $this->attributes['settings'] = json_encode($settings);
0 ignored issues
show
Bug Best Practice introduced by
The property attributes does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
33
    }
34
}
35