Passed
Push — master ( f0ed0e...da797a )
by Gombos
01:32
created

src/Traits/HasSettingsField.php (1 issue)

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);
28
    }
29
30
    public function setSettingsAttribute($settings)
31
    {
32
        $this->attributes['settings'] = json_encode($settings);
33
    }
34
}
35