Deduplicate PHP version branching in RectorConfigBuilder - #8229
Merged
Conversation
withPhpSets() mapped 16 bool arguments to a target version with nine
"if ($phpNN) { $this->withPhpNNSets(); return $this; }" blocks followed by a
seven-branch elseif chain. withDowngradeSets() had the same shape with nine
branches. Both become an array_filter() over a version-keyed map.
The nine withPhpNNSets() methods repeated the same three statements each.
Extract them into a private addPhpLevelSets() helper, which withPhpSets()
now shares.
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.
Follow-up to #8225, same class, same kind of copy-paste.
withPhpSets()16 bool flags were dispatched through nine early-return blocks followed by a seven-arm
elseifchain:Now one version-keyed table:
which also drops the
func_get_args()indirection previously needed to count how many flags were set. The unreachable'Invalid PHP version set'branch goes with it — by that point a non-empty pick list always has exactly one entry.withDowngradeSets()Same shape, nine arms:
The nine
withPhpNNSets()methodsEach had the same three-line body:
becomes
withPhpSets()reuses the same private helper for both the picked-version and the composer.json-resolved path.Behavior
Public API unchanged, and unlike #8225 no message or exception type changes here.
These paths have no direct test coverage, so I checked parity by driving the builder through 14 cases and reading back the resolved set list by reflection on both old and new code: no args, each of
php53/php74/php80/php86, explicitphp80: false, thewithPhpNNSets()equivalents, both downgrade targets, and the four throwing cases (two versions picked,withPhpSets()called twice, no downgrade target, two downgrade targets). Output identical across all 14.Net
-83lines.