Total Complexity | 6 |
Total Lines | 57 |
Duplicated Lines | 0 % |
Coverage | 95.65% |
Changes | 0 |
1 | <?php |
||
7 | class DefaultsManager |
||
8 | { |
||
9 | /** |
||
10 | * @return array |
||
11 | */ |
||
12 | 7 | public function defaults() |
|
13 | { |
||
14 | 7 | $settings = $this->settings(); |
|
15 | 7 | $defaults = (array) array_combine(array_keys($settings), glsr_array_column($settings, 'default')); |
|
16 | 7 | return wp_parse_args($defaults, [ |
|
17 | 7 | 'version' => '', |
|
18 | 'version_upgraded_from' => '', |
||
19 | ]); |
||
20 | } |
||
21 | |||
22 | /** |
||
23 | * @return array |
||
24 | */ |
||
25 | 7 | public function get() |
|
26 | { |
||
27 | 7 | return glsr(Helper::class)->convertDotNotationArray($this->defaults()); |
|
28 | } |
||
29 | |||
30 | /** |
||
31 | * @return array |
||
32 | */ |
||
33 | 7 | public function set() |
|
34 | { |
||
35 | 7 | $settings = glsr(OptionManager::class)->all(); |
|
36 | 7 | $currentSettings = glsr(Helper::class)->removeEmptyArrayValues($settings); |
|
37 | 7 | $defaultSettings = array_replace_recursive($this->get(), $currentSettings); |
|
38 | 7 | $updatedSettings = array_replace_recursive($settings, $defaultSettings); |
|
39 | 7 | update_option(OptionManager::databaseKey(), $updatedSettings); |
|
40 | 7 | return $defaultSettings; |
|
41 | } |
||
42 | |||
43 | /** |
||
44 | * @return array |
||
45 | */ |
||
46 | 7 | public function settings() |
|
47 | { |
||
48 | 7 | $settings = apply_filters('site-reviews/addon/settings', glsr()->config('settings')); |
|
49 | 7 | return $this->normalize($settings); |
|
50 | } |
||
51 | |||
52 | /** |
||
53 | * @return array |
||
54 | */ |
||
55 | protected function normalize(array $settings) |
||
64 | } |
||
65 | } |
||
66 |