Setting::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Albert221\Blog\Entity;
4
5
use DateTime;
6
7
/**
8
 * @Entity(repositoryClass="\Albert221\Blog\Repository\Database\SettingRepository") @Table(name="settings")
9
 */
10
class Setting
11
{
12
    const TYPE_VARCHAR = 0;
13
    const TYPE_INTEGER = 1;
14
    const TYPE_TEXT = 2;
15
    const TYPE_DATETIME = 3;
16
    const TYPE_BOOLEAN = 4;
17
18
    /**
19
     * @var int Id
20
     * @Id @Column(type="integer") @GeneratedValue
21
     */
22
    protected $id;
23
24
    /**
25
     * @var string Name
26
     * @Column(type="string")
27
     */
28
    protected $name;
29
30
    /**
31
     * @var string Value
32
     * @Column(type="string")
33
     */
34
    protected $value;
35
36
    /**
37
     * @var int Type
38
     * @Column(type="integer")
39
     */
40
    protected $type;
41
42
    public function getId()
43
    {
44
        return $this->id;
45
    }
46
47
    public function getName()
48
    {
49
        return $this->name;
50
    }
51
52
    public function setName($name)
53
    {
54
        $this->name = $name;
55
    }
56
57
    public function getValue()
58
    {
59
        switch ($this->type) {
60
            case self::TYPE_INTEGER:
61
                return intval($this->value);
62
            case self::TYPE_DATETIME:
63
                return new DateTime($this->value);
64
            case self::TYPE_BOOLEAN:
65
                return boolval($this->value);
66
            default:
67
                return $this->value;
68
        }
69
    }
70
71
    public function setValue($value)
72
    {
73
        $this->value = $value;
74
    }
75
76
    public function getType()
77
    {
78
        return $this->type;
79
    }
80
81
    public function setType($type)
82
    {
83
        if (!in_array($type, [
84
            self::TYPE_VARCHAR,
85
            self::TYPE_INTEGER,
86
            self::TYPE_TEXT,
87
            self::TYPE_DATETIME,
88
            self::TYPE_BOOLEAN])) {
89
            throw new \InvalidArgumentException('Invalid type given.');
90
        }
91
        
92
        $this->type = $type;
93
    }
94
95
    public function __toString()
96
    {
97
        return $this->getValue();
98
    }
99
}
100