Skip to content

Refine early return else sniff to also change functions with code bef…#2823

Merged
Crabcyborg merged 3 commits into
masterfrom
refine_early_return_else_sniff_to_also_change_functions_with_code_before_the_if
Jan 16, 2026
Merged

Refine early return else sniff to also change functions with code bef…#2823
Crabcyborg merged 3 commits into
masterfrom
refine_early_return_else_sniff_to_also_change_functions_with_code_before_the_if

Conversation

@Crabcyborg
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg commented Jan 16, 2026

…ore the if

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of form field options when exceeding dropdown limits with better autocomplete rendering.
    • Enhanced custom style import resolution to prevent data inconsistencies.
  • Refactor

    • Optimized internal control flow and early exit patterns for improved code clarity.
    • Updated code analysis tools to better detect and suggest control flow improvements.

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 16, 2026

Warning

Rate limit exceeded

@Crabcyborg has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 5 minutes and 6 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 770e242 and b81f6e5.

📒 Files selected for processing (1)
  • phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/FlipIfElseToEarlyReturnSniff.php
📝 Walkthrough

Walkthrough

Control flow refactoring across multiple helpers and PHP CodeSniffer sniffs introduces early returns, restructures if/else logic paths, and enhances sniff detection for conditional transformation. Changes affect dropdown/autocomplete selection, filter invocation timing, XML style import handling, and add comprehensive if/else-to-early-return detection and transformation capabilities.

Changes

Cohort / File(s) Summary
Form/Application Helpers
classes/helpers/FrmAppHelper.php, classes/helpers/FrmFieldsHelper.php, classes/helpers/FrmXMLHelper.php
Restructured control flow across multiple functions using early returns. maybe_autocomplete_options now returns early when sources exceed dropdown limit, building full options array explicitly. prepare_action_slashes replaces else-branch logic with early return. prepare_front_field moves filter handling to preserve edit-path invocation. update_custom_style_setting_on_import refactored with early exits for numeric custom styles and failed lookups.
PHP CodeSniffer Sniff
phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/FlipIfElseToEarlyReturnSniff.php
Added new private methods: findIfElseAtEndOfFunction, applyFlipFix, negateCondition. Updated blockEndsWithReturn signature to accept generic $blockToken. Enhanced applyFix with dedentation/repositioning logic. Implemented dual-case handling: early return for void functions with large else blocks, and condition-flip for else-ending-function scenarios. Improved detection of if/else structures at function end.
PHPCS Ruleset Configuration
phpcs-sniffs/Formidable/ruleset.xml
Reordered and adjusted rule entries: Formidable.CodeAnalysis.SimplifyEmptyTernary retained, Formidable.CodeAnalysis.RedundantEmptyAfterTypeCheck removed, Formidable.CodeAnalysis.MoveVariableBelowEarlyReturn repositioned after PreferArrayKeyFirstLast.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Poem

🐰 Through winding control flows, a rabbit did hop,
Early returns planted—the nesting did stop!
If-elses now flip when the sniff takes a peek,
Helpers refined for code that's quite sleek,
Refactored and clean, our victory's unique! ✨

🚥 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 'Refine early return else sniff to also change functions with code bef…' directly relates to the primary change: enhancing the FlipIfElseToEarlyReturnSniff to handle functions with code before the if/else structure, as evidenced by the substantial refactoring in the sniff file.
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.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 16, 2026

Codecov Report

❌ Patch coverage is 11.62791% with 38 lines in your changes missing coverage. Please review.
✅ Project coverage is 27.09%. Comparing base (c95b629) to head (b81f6e5).
⚠️ Report is 14 commits behind head on master.

Files with missing lines Patch % Lines
classes/helpers/FrmXMLHelper.php 0.00% 22 Missing ⚠️
classes/helpers/FrmAppHelper.php 15.78% 16 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##             master    #2823   +/-   ##
=========================================
  Coverage     27.09%   27.09%           
  Complexity     8840     8840           
=========================================
  Files           145      145           
  Lines         29758    29770   +12     
=========================================
+ Hits           8062     8066    +4     
- Misses        21696    21704    +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Crabcyborg Crabcyborg merged commit 6de8ab7 into master Jan 16, 2026
17 of 18 checks passed
@Crabcyborg Crabcyborg deleted the refine_early_return_else_sniff_to_also_change_functions_with_code_before_the_if branch January 16, 2026 18:16
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