Passed
Push — master ( b54e8f...ab9cd5 )
by Gombos
03:13
created

FieldSettingsManager::set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Glorand\Model\Settings\Managers;
4
5
use Glorand\Model\Settings\Contracts\SettingsManagerContract;
6
7
/**
8
 * Class FieldSettingsManager
9
 * @package Glorand\Model\Settings\Managers
10
 * @property \Illuminate\Database\Eloquent\Model|\Glorand\Model\Settings\Traits\HasSettingsField $model
11
 */
12
class FieldSettingsManager extends AbstractSettingsManager
13
{
14
    /**
15
     * @param array $settings
16
     * @return \Glorand\Model\Settings\Contracts\SettingsManagerContract
17
     */
18 36
    public function apply(array $settings = []): SettingsManagerContract
19
    {
20 36
        $this->model->{$this->model->getSettingsFieldName()} = json_encode($settings);
21 36
        if ($this->model->isPersistSettings()) {
22 36
            $this->model->save();
23
        }
24
25 36
        return $this;
26
    }
27
}
28