InMemorySettingRepository   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 4
dl 0
loc 54
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A save() 0 4 1
A set() 0 6 2
A __construct() 0 9 2
A findWithinSection() 0 15 2
1
<?php
2
3
namespace Galileo\SettingBundle\Lib\Infrastructure\Internal;
4
5
use Galileo\SettingBundle\Lib\Model\Setting;
6
use Galileo\SettingBundle\Lib\Model\SettingRepositoryInterface;
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 InMemorySettingRepository implements SettingRepositoryInterface
12
{
13
    private $values = [];
14
15
16 7
    public function __construct($settingPlainRows)
17
    {
18 7
        foreach ($settingPlainRows as $key) {
19 7
            $name = $key[0];
20 7
            $value = $key[1];
21 7
            $section = $key[2];
22 7
            $this->set($name, $value, $section);
23
        }
24 7
    }
25
26
    /**
27
     * {@inheritdoc}
28
     */
29 6
    public function findWithinSection(Key $settingKey, Section $section)
30
    {
31 6
        $key = $settingKey->key();
32 6
        $sectionName = $section->name();
33
34 6
        if (!isset($this->values[$key][$sectionName])) {
35 3
            return null;
36
        }
37
38 4
        return Setting::issue(
39
            $settingKey,
40 4
            $this->values[$key][$sectionName],
41 4
            new Section($sectionName)
42
        );
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 2
    public function save(Setting $setting)
49
    {
50 2
        $this->set($setting->name(), $setting->value(), $setting->section());
51 2
    }
52
53
    /**
54
     * @param $name
55
     * @param $value
56
     * @param $section
57
     */
58 7
    private function set($name, $value, $section)
59
    {
60 7
        $section = $section ? $section : Section::EMPTY_SECTION;
61
62 7
        $this->values[$name][$section] = new Value($value);
63 7
    }
64
}
65