Passed
Push — master ( 1cbff4...e83acc )
by
02:22
created

Section   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 63.33%

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 1
dl 0
loc 109
ccs 19
cts 30
cp 0.6333
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 3
A initSettings() 0 6 2
A isOwnerAware() 0 4 1
A isEnabled() 0 4 1
A getLabel() 0 4 1
A getDescription() 0 4 1
A getName() 0 4 1
A getSetting() 0 8 2
A getSettings() 0 4 1
A jsonSerialize() 0 6 1
1
<?php
2
3
/*
4
 * This file is part of the PhpMob package.
5
 *
6
 * (c) Ishmael Doss <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace PhpMob\Settings\Schema;
15
16
/**
17
 * @author Ishmael Doss <[email protected]>
18
 */
19
class Section implements \JsonSerializable
20
{
21
    /**
22
     * @var array
23
     */
24
    private $data = [];
25
26
    /**
27
     * @var SettingSchema[]
28
     */
29
    private $settings = [];
30
31 9
    public function __construct($name, array $data)
32
    {
33 9
        $this->data['name'] = $name;
34
35 9
        foreach ($data as $key => $value) {
36 9
            if ('settings' === $key) {
37 9
                $this->initSettings($value);
38
            } else {
39 9
                $this->data[$key] = $value;
40
            }
41
        }
42 9
    }
43
44
    /**
45
     * @param array $settings
46
     */
47 9
    private function initSettings(array $settings)
48
    {
49 9
        foreach ($settings as $schemaKey => $schemaData) {
50 9
            $this->settings[$schemaKey] = new SettingSchema($this, $schemaKey, $schemaData);
51
        }
52 9
    }
53
54
    /**
55
     * @return bool
56
     */
57
    public function isOwnerAware()
58
    {
59
        return $this->data['owner_aware'];
60
    }
61
62
    /**
63
     * @return bool
64
     */
65
    public function isEnabled()
66
    {
67
        return $this->data['enabled'];
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getLabel()
74
    {
75
        return $this->data['label'];
76
    }
77
78
    /**
79
     * @return string
80
     */
81
    public function getDescription()
82
    {
83
        return $this->data['description'];
84
    }
85
86
    /**
87
     * @return string
88
     */
89 9
    public function getName()
90
    {
91 9
        return $this->data['name'];
92
    }
93
94
    /**
95
     * @param string $key
96
     *
97
     * @return SettingSchema
98
     *
99
     * @throws \InvalidArgumentException
100
     */
101 2
    public function getSetting($key)
102
    {
103 2
        if (!array_key_exists($key, $this->settings)) {
104 1
            throw new \InvalidArgumentException("No setting key `$key` in this section.`");
105
        }
106
107 1
        return $this->settings[$key];
108
    }
109
110
    /**
111
     * @return SettingSchema[]
112
     */
113 3
    public function getSettings()
114
    {
115 3
        return array_values($this->settings);
116
    }
117
118
    /**
119
     * {@inheritdoc}
120
     */
121
    public function jsonSerialize()
122
    {
123
        return array_merge($this->data, [
124
            'settings' => $this->settings,
125
        ]);
126
    }
127
}
128