Completed
Pull Request — master (#10)
by Kamil
02:45
created

Setting   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 4
dl 0
loc 73
ccs 0
cts 42
cp 0
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A issue() 0 4 1
A __construct() 0 6 1
A name() 0 4 1
A value() 0 4 1
A section() 0 4 1
A changeValue() 0 10 2
A setKey() 0 4 1
A setSection() 0 4 1
A setValue() 0 4 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
    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