Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions bluem.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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() {
Expand Down
5 changes: 2 additions & 3 deletions docs/refactor-increments.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
17 changes: 17 additions & 0 deletions src/Settings/BluemOptionLookup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Bluem\Wordpress\Settings;

final class BluemOptionLookup
{
public function __construct(private readonly array $options)
{
}

public function get($key): mixed
{
return array_key_exists($key, $this->options)
? $this->options[$key]
: false;
}
}
25 changes: 25 additions & 0 deletions tests/Unit/BluemOptionLookupTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Unit;

use Bluem\Wordpress\Settings\BluemOptionLookup;
use PHPUnit\Framework\TestCase;

final class BluemOptionLookupTest extends TestCase
{
public function testItReturnsConfiguredOptions(): void
{
$lookup = new BluemOptionLookup([
'environment' => ['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'));
}
}
Loading