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