Skip to content

Allow the if-true-return-false pattern#43

Merged
rieschl merged 1 commit into
masterfrom
worktree-fixes
May 18, 2026
Merged

Allow the if-true-return-false pattern#43
rieschl merged 1 commit into
masterfrom
worktree-fixes

Conversation

@MidnightDesign
Copy link
Copy Markdown
Contributor

Summary

  • Disables PHP CS Fixer's 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.
  • Disables the Slevomat counterpart UselessIfConditionWithReturn so both formatters agree that the pattern is allowed.
  • Moves useless-if-with-return.php from tests/fixtures/invalid/ to tests/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 skips
  • bash tests/check-sa-overlap.sh — SA intersection unchanged

🤖 Generated with Claude Code

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>
Copy link
Copy Markdown

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

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_return rule from the configured ruleset.
  • Removes Slevomat’s UselessIfConditionWithReturn rule from the PHPCS ruleset.
  • Moves the useless-if-with-return.php fixture from invalid/ to valid/ 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.

Comment thread php-cs-fixer-rules.php
'self_accessor' => true,
'simplified_if_return' => true,
'single_quote' => true,
'single_space_around_construct' => true,
@rieschl rieschl merged commit ff2a875 into master May 18, 2026
12 checks passed
@rieschl rieschl deleted the worktree-fixes branch May 18, 2026 14:59
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.

3 participants