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

HasSettingsField   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 20
ccs 0
cts 11
cp 0
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getSettingsAttribute() 0 3 1
A setSettingsAttribute() 0 3 1
A settings() 0 3 2
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