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