refactor: extract apply_pending_provider_change helper#17
Merged
Conversation
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
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 inWPVDB\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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Extracts the settings mutation shared by
ajax_confirm_provider_change()andhandle_apply_provider_change()into a privateapply_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-providerdefault_model, and clearpending_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:
update_option( ..., normalize() )thenCache::invalidate_query_cache().update_option( ..., normalize(), true )(autoload) plusdelete_transient()+wp_cache_delete()thenCache::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 -lclean.phpcs --standard=phpcs.xml.distintroduces 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