Skip to content

New sniff to change if else in loop to continue when if condition is …#2833

Merged
Crabcyborg merged 2 commits into
masterfrom
new_sniff_to_change_if_else_in_loop_to_continue
Jan 19, 2026
Merged

New sniff to change if else in loop to continue when if condition is …#2833
Crabcyborg merged 2 commits into
masterfrom
new_sniff_to_change_if_else_in_loop_to_continue

Conversation

@Crabcyborg
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg commented Jan 19, 2026

…larger than else

Summary by CodeRabbit

  • Refactor

    • Streamlined control flow and data handling across form formatting, CSV/repeater headings, metadata updates, and event processing to improve clarity and consistency.
  • Chores

    • Added an automated code-analysis rule to detect and refactor end-of-loop conditional patterns.
    • Pinned a dev dependency version in the project manifest.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 19, 2026

📝 Walkthrough

Walkthrough

Adds a new PHP_CodeSniffer sniff that flips end-of-loop if/else blocks to use negated conditions with early continue, and applies this control-flow inversion across several helpers, models, and controllers to simplify first-occurrence handling and reduce nesting.

Changes

Cohort / File(s) Summary
Code Analysis Sniff
phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/FlipLoopIfElseToContinueSniff.php, phpcs-sniffs/Formidable/ruleset.xml
New PHPCS sniff registered in the ruleset that detects large end-of-loop if blocks with small else blocks and auto-fixes by negating conditions, inserting continue, and dedenting code. Configurable thresholds: minIfLines, maxElseLines.
Helpers — duplicate-key & repeater handling
classes/helpers/FrmAppHelper.php, classes/helpers/FrmCSVExportHelper.php
Inverted conditional flow to handle first-occurrence cases early (using continue), restructured aggregation for duplicate input names and repeater heading expansion; logic reordered but final data structures preserved.
Models — entry meta updates
classes/models/FrmEntryMeta.php
update_entry_metas reorders checks to treat non-existent fields first (strict in_array), creating metas early and continuing; existing-field path then handles blanks or updates.
Square integration controllers
square/controllers/FrmSquareLiteAppController.php, square/controllers/FrmSquareLiteEventsController.php
Flipped guards to early-continue on non-target cases (non-item_meta, non-object events); main processing now runs only for valid items/events.
Stripe integration — controllers & auth
stripe/controllers/FrmStrpLiteEventsController.php, stripe/models/FrmStrpLiteAuth.php
Similar control-flow flips: early-continue for invalid events or non-item_meta; format_form_data reorders first-assignment vs aggregation for duplicate keys.
Tooling / dev deps
composer.json
Tightened phpstan dev dependency from caret range to exact version (2.1.33).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 I hopped through loops with nimble paws,
Flipped ifs to continues without a pause.
I negated conditions, tidied the nest,
Less nesting now — my code's well-dressed.
Hop, hop — refactor done, time for a rest! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: introducing a new sniff that refactors if/else constructs in loops to use continue when the if block is larger than the else block.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Crabcyborg Crabcyborg merged commit d29de43 into master Jan 19, 2026
15 of 16 checks passed
@Crabcyborg Crabcyborg deleted the new_sniff_to_change_if_else_in_loop_to_continue branch January 19, 2026 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant