Test Failed
Pull Request — master (#1563)
by
unknown
09:08
created

SettingsModel::saveUpdate()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 13
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 5
nc 6
nop 1
dl 0
loc 13
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace FacturaScripts\Core\Model;
4
5
class SettingsModel extends Base\ModelClass
6
{
7
    use Base\ModelTrait;
0 ignored issues
show
Bug introduced by
The trait FacturaScripts\Core\Model\Base\ModelTrait requires the property $name which is not provided by FacturaScripts\Core\Model\SettingsModel.
Loading history...
8
9
    /** @var int */
10
    public $id;
11
12
    /** @var string */
13
    public $classnamemodel;
14
15
    /** @var string */
16
    public $idmodel;
17
18
    /** @var string */
19
    public $idempresa;
20
21
    /** @var array */
22
    public $settings;
23
24
    public static function primaryColumn(): string
25
    {
26
        return 'id';
27
    }
28
29
    public static function tableName(): string
30
    {
31
        return 'settings_model';
32
    }
33
34
    public function loadFromData(array $data = [], array $exclude = []): void
35
    {
36
        parent::loadFromData($data, ['settings', 'action']);
37
        $this->settings = isset($data['settings']) ? json_decode($data['settings'], true) : [];
38
    }
39
40
    protected function saveUpdate(array $values = []): bool
41
    {
42
        // agregamos a la propiedad settings las propiedades que hay en el modelo
43
        // y que nos vienen de la request/inputs
44
        foreach ($this->settings as $key => $value) {
45
            $this->settings[$key] = empty($this->{$key}) ? null : $this->{$key};
46
        }
47
48
        if (is_array($this->settings)) {
0 ignored issues
show
introduced by
The condition is_array($this->settings) is always true.
Loading history...
49
            $this->settings = json_encode($this->settings);
0 ignored issues
show
Documentation Bug introduced by
It seems like json_encode($this->settings) of type string is incompatible with the declared type array of property $settings.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
50
        }
51
52
        return parent::saveUpdate($values);
53
    }
54
}
55