Setting::setKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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