[CodeQuality] Move 4 early-return rules to code quality set - #8301
Merged
Conversation
TomasVotruba
force-pushed
the
move-early-return-rules-to-code-quality
branch
2 times, most recently
from
August 5, 2026 22:41
e00c35a to
beef2df
Compare
RemoveAlwaysElseRector, ChangeIfElseValueAssignToEarlyReturnRector, PreparedValueToEarlyReturnRector and ReturnEarlyIfVariableRector improve local code quality rather than enforce the early-return style. Move their set registration from early-return to CodeQualityLevel. The rule classes stay in their current namespace.
TomasVotruba
force-pushed
the
move-early-return-rules-to-code-quality
branch
from
August 5, 2026 22:47
beef2df to
1c8f0b7
Compare
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.
These 4 rules clean up local code quality rather than enforce the early-return coding style. Move their set registration from
early-returntoCodeQualityLevel::RULES(right afterInlineArrayReturnAssignRector, same "assign then return" family).Set membership only - the rule classes stay in
Rector\EarlyReturn\*, no namespace change.RemoveAlwaysElseRector:class SomeClass { public function run($value) { if ($value) { throw new \InvalidStateException; - } else { - return 10; } + + return 10; } }ChangeIfElseValueAssignToEarlyReturnRector:class SomeClass { public function run() { if ($this->hasDocBlock($tokens, $index)) { - $docToken = $tokens[$this->getDocBlockIndex($tokens, $index)]; - } else { - $docToken = null; + return $tokens[$this->getDocBlockIndex($tokens, $index)]; } - return $docToken; + return null; } }PreparedValueToEarlyReturnRector:class SomeClass { public function run() { - $var = null; - if (rand(0, 1)) { - $var = 1; + return 1; } if (rand(0, 1)) { - $var = 2; + return 2; } - return $var; + return null; } }ReturnEarlyIfVariableRector:class SomeClass { public function run($value) { if ($value) { - $variable = 'yes'; - } else { - $variable = 'no'; + return 'yes'; } - return $variable; + return 'no'; } }One unrelated hunk:
InlineConstructorDefaultToPropertyRectorhad a pre-existing ECS violation onmain(missing space in an arrow fn);composer fix-cscorrected it, so it rides along.