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