Allow the if-true-return-false pattern#43
Merged
Merged
Conversation
PHP CS Fixer's `simplified_if_return` produced malformed output (trailing semicolons on their own line, gratuitous `(bool)` casts, extra wrapping parens). Both that rule and its Slevomat counterpart `UselessIfConditionWithReturn` are now disabled, and the fixture moves from invalid to valid with a comment explaining why the pattern is useful — it keeps multiple boolean-returning if-branches visually consistent. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Disables the PHP CS Fixer and PHPCS/Slevomat rules that auto-simplify if (cond) { return true; } return false;, allowing that pattern to remain for consistency in multi-branch boolean-returning functions.
Changes:
- Removes PHP CS Fixer’s
simplified_if_returnrule from the configured ruleset. - Removes Slevomat’s
UselessIfConditionWithReturnrule from the PHPCS ruleset. - Moves the
useless-if-with-return.phpfixture frominvalid/tovalid/and documents the rationale in-file.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
php-cs-fixer-rules.php |
Stops enabling the simplified_if_return fixer so the pattern is permitted. |
Eventjet/ruleset.xml |
Drops the Slevomat sniff that would otherwise forbid the pattern under PHPCS. |
tests/fixtures/valid/useless-if-with-return.php |
Adds/keeps a valid fixture demonstrating and explaining why the pattern is allowed. |
tests/fixtures/invalid/useless-if-with-return.php |
Removes the prior invalid fixture now that the pattern is allowed. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 'self_accessor' => true, | ||
| 'simplified_if_return' => true, | ||
| 'single_quote' => true, | ||
| 'single_space_around_construct' => true, |
rieschl
approved these changes
May 18, 2026
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
simplified_if_return(added in Add invalid fixtures and close per-tool rule gaps #41) — its fixer produces malformed output: trailing;on its own line, gratuitous(bool)casts, and extra wrapping parens.UselessIfConditionWithReturnso both formatters agree that the pattern is allowed.useless-if-with-return.phpfromtests/fixtures/invalid/totests/fixtures/valid/with a comment explaining the rationale (consistency across multiple boolean-returning if-branches).Test plan
vendor/bin/phpunit tests/RulesTest.php— 206 tests, 18 expected skipsbash tests/check-sa-overlap.sh— SA intersection unchanged🤖 Generated with Claude Code