diff --git a/bluem.php b/bluem.php index e0e7305..4f00de8 100644 --- a/bluem.php +++ b/bluem.php @@ -54,6 +54,7 @@ use Bluem\Wordpress\Requests\BluemEnabledRequestTypeFilter; use Bluem\Wordpress\Support\BluemSupportReportEnvironment; use Bluem\Wordpress\Support\BluemComposerDependencyVersion; +use Bluem\Wordpress\Settings\BluemOptionLookup; use Bluem\Wordpress\Support\BluemSupportReportTrace; /** @@ -1472,13 +1473,7 @@ function bluem_woocommerce_show_general_profile_fields() { // Settings functions function bluem_woocommerce_get_option( $key ) { - $options = bluem_woocommerce_get_core_options(); - - if ( array_key_exists( $key, $options ) ) { - return $options[ $key ]; - } - - return false; + return (new BluemOptionLookup(bluem_woocommerce_get_core_options()))->get($key); } function bluem_woocommerce_settings_render_environment() { diff --git a/docs/refactor-increments.md b/docs/refactor-increments.md index 587bc7b..b164193 100644 --- a/docs/refactor-increments.md +++ b/docs/refactor-increments.md @@ -10,9 +10,9 @@ functions as compatibility adapters during the migration. 4. [x] Extract request grouping into `BluemRequestGrouper`. 5. [x] Extract enabled request-type filtering into `BluemEnabledRequestTypeFilter`. 6. [x] Extract Composer dependency version lookup into a testable support service. -7. [ ] Extract support-report environment collection behind injectable WordPress and WooCommerce readers. +7. [x] Extract support-report environment collection behind injectable WordPress and WooCommerce readers. 8. [x] Extract support-report trace normalization into a pure trace formatter. -9. [ ] Extract core plugin option lookup into a small settings accessor. +9. [x] Extract core plugin option lookup into a small settings accessor. 10. [ ] Extract core plugin option definitions into a settings schema object. 11. [ ] Extract payment, mandate, and iDIN settings access behind feature-specific settings objects. 12. [ ] Extract Bluem request persistence from `bluem-db.php` into a request repository. @@ -23,4 +23,3 @@ functions as compatibility adapters during the migration. 17. [ ] Extract Contact Form 7 and Gravity Forms flows into integration adapters. 18. [ ] Move admin request rendering and navigation behind presentation services. -The next increment is core plugin option lookup. diff --git a/src/Settings/BluemOptionLookup.php b/src/Settings/BluemOptionLookup.php new file mode 100644 index 0000000..439813d --- /dev/null +++ b/src/Settings/BluemOptionLookup.php @@ -0,0 +1,17 @@ +options) + ? $this->options[$key] + : false; + } +} diff --git a/tests/Unit/BluemOptionLookupTest.php b/tests/Unit/BluemOptionLookupTest.php new file mode 100644 index 0000000..7405322 --- /dev/null +++ b/tests/Unit/BluemOptionLookupTest.php @@ -0,0 +1,25 @@ + ['default' => 'test'], + 'senderID' => ['default' => ''], + ]); + + self::assertSame(['default' => 'test'], $lookup->get('environment')); + self::assertSame(['default' => ''], $lookup->get('senderID')); + } + + public function testMissingOptionsReturnFalseForCompatibility(): void + { + self::assertFalse((new BluemOptionLookup([]))->get('missing')); + } +}