Skip to content

refactor: extract apply_pending_provider_change helper#17

Merged
rbcorrales merged 1 commit into
mainfrom
refactor/extract-apply-pending-provider-change
May 27, 2026
Merged

refactor: extract apply_pending_provider_change helper#17
rbcorrales merged 1 commit into
mainfrom
refactor/extract-apply-pending-provider-change

Conversation

@rbcorrales
Copy link
Copy Markdown
Member

Summary

Extracts the settings mutation shared by ajax_confirm_provider_change() and handle_apply_provider_change() into a private apply_pending_provider_change( $settings, $new_provider, $new_model ) helper that returns the mutated settings. Both call sites now call the helper instead of repeating the block.

The helper covers only the genuinely identical part: set active_provider / active_model / provider, mirror the model into the matching per-provider default_model, and clear pending_provider / pending_model.

Background

The two paths carried a verbatim copy of that mutation. Their persistence tails, however, are NOT identical, so they are intentionally left at each call site:

  • AJAX path: update_option( ..., normalize() ) then Cache::invalidate_query_cache().
  • Admin-post path: update_option( ..., normalize(), true ) (autoload) plus delete_transient() + wp_cache_delete() then Cache::invalidate_query_cache().

Folding those into the helper would have changed behavior on one path, so the refactor is scoped to the shared mutation only. Adding a future provider now means touching one place for the activation logic.

Testing

php -l clean. phpcs --standard=phpcs.xml.dist introduces zero new violations (30 errors / 41 warnings before and after, all pre-existing baseline). Verified the helper is defined once and called from both sites, with each call site's distinct persistence tail preserved.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Pure refactor extracting duplicated provider/model activation logic from two apply paths into a private helper, leaving each path's distinct persistence/cache-clearing behavior in place.

Changes:

  • Adds private apply_pending_provider_change() helper in WPVDB\Admin.
  • Replaces the duplicated mutation block in ajax_confirm_provider_change() with a helper call.
  • Replaces the duplicated mutation block in handle_apply_provider_change() with a helper call.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@rbcorrales rbcorrales merged commit f2af4bf into main May 27, 2026
1 check passed
@rbcorrales rbcorrales deleted the refactor/extract-apply-pending-provider-change branch May 28, 2026 02:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants