Completed
Push — master ( 982f0c...377cb6 )
by Kamil
05:13 queued 02:16
created

Setting::value()   A

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 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Galileo\SettingBundle\Lib\Model;
4
5
use Galileo\SettingBundle\Lib\Model\Event\EventAggregateInterface;
6
use Galileo\SettingBundle\Lib\Model\Event\EventAggregateTrait;
7
use Galileo\SettingBundle\Lib\Model\ValueObject\Key;
8
use Galileo\SettingBundle\Lib\Model\ValueObject\Section;
9
use Galileo\SettingBundle\Lib\Model\ValueObject\Value;
10
11
class Setting implements EventAggregateInterface
12
{
13
    use EventAggregateTrait;
14
15
    protected $name;
16
    protected $value;
17
    protected $section;
18
19
    public static function issue(Key $name, Value $value, Section $section)
20
    {
21
        return new Setting($name, $value, $section);
22
    }
23
24
    public function __construct(Key $key, Value $value, Section $section)
25
    {
26
        $this->setKey($key);
27
        $this->setValue($value);
28
        $this->setSection($section);
29
    }
30
31
    public function name()
32
    {
33
        return $this->name;
34
    }
35
36
    public function value()
37
    {
38
        return $this->value;
39
    }
40
41
    public function section()
42
    {
43
        return $this->section;
44
    }
45
46
    /**
47
     * @param Value $value
48
     */
49
    public function changeValue(Value $value)
50
    {
51
        $internalValue = new Value($this->value);
52
53
        if ($value->equalsTo($internalValue)) {
54
            return;
55
        }
56
57
        $this->setValue($value);
58
    }
59
60
    /**
61
     * @param Key $key
62
     */
63
    private function setKey(Key $key)
64
    {
65
        $this->name = $key->key();
66
    }
67
68
    /**
69
     * @param Section $section
70
     */
71
    private function setSection(Section $section)
72
    {
73
        $this->section = $section->name();
74
    }
75
76
    /**
77
     * @param Value $value
78
     */
79
    private function setValue(Value $value)
80
    {
81
        $this->value = $value->value();
82
    }
83
}
84