Completed
Push — settings-management ( 58b7ea )
by Fèvre
06:34 queued 06:34
created

SettingPresenter::getTypeAttribute()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
c 0
b 0
f 0
nc 4
nop 0
dl 0
loc 15
rs 10
1
<?php
2
namespace Xetaravel\Models\Presenters;
3
4
trait SettingPresenter
5
{
6
    /**
7
     * Attribute the value regardless to the type.
8
     *
9
     * @return int|bool|string
10
     */
11
    public function getValueAttribute()
12
    {
13
        if (!is_null($this->value_int)) {
14
            return intval($this->value_int);
15
        }
16
17
        if (!is_null($this->value_bool)) {
18
            return boolval($this->value_bool);
19
        }
20
21
        if (!is_null($this->value_str)) {
22
            return $this->value_str;
23
        }
24
25
        return null;
26
    }
27
28
    /**
29
     * Get the type of the value.
30
     *
31
     * @return int|bool|string
32
     */
33
    public function getTypeAttribute()
34
    {
35
        if (!is_null($this->value_int)) {
36
            return $this->type = "value_int";
0 ignored issues
show
Bug Best Practice introduced by
The property type does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
37
        }
38
39
        if (!is_null($this->value_bool)) {
40
            return $this->type = "value_bool";
41
        }
42
43
        if (!is_null($this->value_str)) {
44
            return $this->type = "value_str";
45
        }
46
47
        return null;
48
    }
49
}
50