Skip to content

Enforce more early exits#2982

Merged
Crabcyborg merged 2 commits into
masterfrom
enforce_more_early_exits
Feb 26, 2026
Merged

Enforce more early exits#2982
Crabcyborg merged 2 commits into
masterfrom
enforce_more_early_exits

Conversation

@Crabcyborg

@Crabcyborg Crabcyborg commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Refactor
    • Widespread control-flow cleanup across controllers, models and helpers: inverted guards and added early-return/early-continue patterns to improve readability and reduce nesting without changing behavior.
  • Style
    • Updated static analysis rule to reflect the new early-exit patterns.
  • Tests
    • Adjusted test guard style to match refactored control-flow approach.

@coderabbitai

coderabbitai Bot commented Feb 26, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This PR refactors conditional control flow across many files, replacing nested positive conditionals with inverted guard clauses (early return/continue) while preserving existing behaviors and signatures. Changes span controllers, helpers, models, extension code, and tests.

Changes

Cohort / File(s) Summary
Controllers
classes/controllers/FrmAddonsController.php, classes/controllers/FrmAppController.php, classes/controllers/FrmDashboardController.php, classes/controllers/FrmEntriesController.php, classes/controllers/FrmFormActionsController.php, classes/controllers/FrmFormTemplatesController.php, classes/controllers/FrmFormsController.php, classes/controllers/FrmInboxController.php, classes/controllers/FrmSettingsController.php
Converted wrapped-if blocks to early-return/continue guards; reordered small checks and moved unsetting/processing accordingly. Watch for changed guard placement in asset enqueuing, inbox/message cleaning, and entry-loading paths.
Helpers
classes/helpers/FrmAppHelper.php, classes/helpers/FrmCSVExportHelper.php, classes/helpers/FrmFieldsHelper.php, classes/helpers/FrmXMLHelper.php, classes/helpers/FrmListHelper.php
Applied early-exit patterns in callbacks, loops, attribute rendering, CSV/repeater meta filling, field-id switching, and XML import flows. Note custom_html special-case handling and attribute short-circuiting.
Core Models
classes/models/FrmAddon.php, classes/models/FrmAntiSpam.php, classes/models/FrmCreateFile.php, classes/models/FrmDb.php, classes/models/FrmEntryFormatter.php, classes/models/FrmEntryValidate.php, classes/models/FrmField.php, classes/models/FrmFieldFormHtml.php, classes/models/FrmFieldValue.php, classes/models/FrmForm.php, classes/models/FrmFormAction.php, classes/models/FrmInbox.php, classes/models/FrmMigrate.php, classes/models/FrmPluginSearch.php, classes/models/FrmSettings.php, classes/models/FrmTableHTMLGenerator.php, classes/models/FrmUsage.php
Refactored various update/validation/migration/helper methods to use guard clauses; many loops now continue early for absent data. Pay attention to file permission checks, caching guard inversion, and form-option sanitization flow.
Field & Specialized Models
classes/models/fields/FrmFieldCombo.php, classes/models/fields/FrmFieldNumber.php, classes/models/fields/FrmFieldType.php
Validation and field-initialization logic inverted to use continues/early returns; special handling for comma removal and type initialization affected.
Stripe Extension
stripe/models/FrmStrpLiteSettings.php, stripe/models/FrmTransLiteDb.php, stripe/helpers/FrmTransLiteAppHelper.php
Parameter presence and migration checks moved to defensive early-continue/return guards; rendering helper short-circuits on falsy values.
Configuration & Tests
phpcs.xml, tests/phpunit/test_wordpress_plugin_tests.php
Removed one phpcs property related to early-exit rule; test guard inverted to early return on callable absence.
Other helpers/models
classes/helpers/..., classes/models/... (multiple small files)
Numerous small guard-pattern refactors across remaining helpers and models (e.g., CSV, XML, entries, formatting).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Hopped through code with nimble toes,

Guards that nip the nesting woes.
Early exits, tidy trail,
Logic clear and tests prevail.
A little hop, a cleaner flow—hip hooray! 🎉

🚥 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 'Enforce more early exits' accurately describes the main change across all modified files—a systematic refactoring that inverts conditional logic to use early returns/continues instead of nested blocks.
Docstring Coverage ✅ Passed Docstring coverage is 96.15% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch enforce_more_early_exits

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.

@deepsource-io

deepsource-io Bot commented Feb 26, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in 63a8183...f2ab032 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

Code Review Summary

Analyzer Status Updated (UTC) Details
PHP Feb 26, 2026 5:57p.m. Review ↗
JavaScript Feb 26, 2026 5:57p.m. Review ↗

@deepsource-io

deepsource-io Bot commented Feb 26, 2026

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in 63a8183...83057e9 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

Important

Some issues found as part of this review are outside of the diff in this pull request and aren't shown in the inline review comments due to GitHub's API limitations. You can see those issues on the DeepSource dashboard.

PR Report Card

Overall Grade  

Focus Area: Hygiene
Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
PHP Feb 26, 2026 6:10p.m. Review ↗
JavaScript Feb 26, 2026 6:10p.m. Review ↗

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
classes/controllers/FrmEntriesController.php (1)

560-560: Remove the unused destructured variable in user_hidden_columns_for_form().

Line 560 assigns $field_key but never uses it, which matches the PHPMD warning and adds avoidable noise.

♻️ Proposed cleanup
-			list( $form_prefix, $field_key ) = explode( '_', $r );
+			list( $form_prefix ) = explode( '_', $r );
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@classes/controllers/FrmEntriesController.php` at line 560, In
user_hidden_columns_for_form() the destructured assignment list( $form_prefix,
$field_key ) = explode( '_', $r ); introduces an unused $field_key; remove the
unused variable by changing the destructuring to only capture $form_prefix (e.g.
use list($form_prefix) = explode('_', $r') or the short array syntax) so the
function no longer declares the unused $field_key and the PHPMD warning is
resolved.
classes/helpers/FrmAppHelper.php (1)

2367-2369: Remove the unused loop value variable.

Line 2367 declares $frm_role_description but never uses it. This is also flagged by PHPMD.

Suggested cleanup
-		foreach ( $frm_roles as $frm_role => $frm_role_description ) {
+		foreach ( array_keys( $frm_roles ) as $frm_role ) {
 			$role->add_cap( $frm_role );
 		}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@classes/helpers/FrmAppHelper.php` around lines 2367 - 2369, The foreach loop
in FrmAppHelper.php declares an unused $frm_role_description variable; update
the loop that iterates over $frm_roles (the block that calls
$role->add_cap($frm_role)) to remove the unused value variable (e.g., iterate
only with $frm_role) so PHPMD warnings are resolved and the loop remains
functionally identical.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@classes/helpers/FrmCSVExportHelper.php`:
- Around line 627-628: The current logic blindly replaces a non-array meta at
$entries[self::$entry->parent_item_id]->metas[$repeater_child->id] with an empty
array; instead, when that meta exists but is not an array, preserve its scalar
value by converting it into an array containing the original scalar (so it isn't
lost) before adding any placeholder/blank entries. Update the check around
$entries[self::$entry->parent_item_id]->metas[$repeater_child->id] to only
initialize to array() if it is unset, and if it exists and !is_array(...) wrap
the existing value into an array containing that value so the original data is
preserved.

---

Nitpick comments:
In `@classes/controllers/FrmEntriesController.php`:
- Line 560: In user_hidden_columns_for_form() the destructured assignment list(
$form_prefix, $field_key ) = explode( '_', $r ); introduces an unused
$field_key; remove the unused variable by changing the destructuring to only
capture $form_prefix (e.g. use list($form_prefix) = explode('_', $r') or the
short array syntax) so the function no longer declares the unused $field_key and
the PHPMD warning is resolved.

In `@classes/helpers/FrmAppHelper.php`:
- Around line 2367-2369: The foreach loop in FrmAppHelper.php declares an unused
$frm_role_description variable; update the loop that iterates over $frm_roles
(the block that calls $role->add_cap($frm_role)) to remove the unused value
variable (e.g., iterate only with $frm_role) so PHPMD warnings are resolved and
the loop remains functionally identical.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 63a8183 and f2ab032.

📒 Files selected for processing (37)
  • classes/controllers/FrmAddonsController.php
  • classes/controllers/FrmAppController.php
  • classes/controllers/FrmDashboardController.php
  • classes/controllers/FrmEntriesController.php
  • classes/controllers/FrmFormActionsController.php
  • classes/controllers/FrmFormTemplatesController.php
  • classes/controllers/FrmFormsController.php
  • classes/controllers/FrmInboxController.php
  • classes/controllers/FrmSettingsController.php
  • classes/helpers/FrmAppHelper.php
  • classes/helpers/FrmCSVExportHelper.php
  • classes/helpers/FrmFieldsHelper.php
  • classes/helpers/FrmXMLHelper.php
  • classes/models/FrmAddon.php
  • classes/models/FrmAntiSpam.php
  • classes/models/FrmCreateFile.php
  • classes/models/FrmDb.php
  • classes/models/FrmEntryFormatter.php
  • classes/models/FrmEntryValidate.php
  • classes/models/FrmField.php
  • classes/models/FrmFieldFormHtml.php
  • classes/models/FrmFieldValue.php
  • classes/models/FrmForm.php
  • classes/models/FrmFormAction.php
  • classes/models/FrmInbox.php
  • classes/models/FrmMigrate.php
  • classes/models/FrmPluginSearch.php
  • classes/models/FrmSettings.php
  • classes/models/FrmTableHTMLGenerator.php
  • classes/models/FrmUsage.php
  • classes/models/fields/FrmFieldCombo.php
  • classes/models/fields/FrmFieldNumber.php
  • classes/models/fields/FrmFieldType.php
  • phpcs.xml
  • stripe/models/FrmStrpLiteSettings.php
  • stripe/models/FrmTransLiteDb.php
  • tests/phpunit/test_wordpress_plugin_tests.php
💤 Files with no reviewable changes (1)
  • phpcs.xml

Comment thread classes/helpers/FrmCSVExportHelper.php

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@stripe/helpers/FrmTransLiteAppHelper.php`:
- Around line 392-394: The guard clause currently uses a loose falsy check on
$value which hides legitimate 0 and '0' values; update the guard in
FrmTransLiteAppHelper.php to only return for truly absent values (e.g. null or
empty string) rather than any falsy value so calls like
show_in_table($subscription->fail_count, ...) will display 0; locate the block
using the $value variable and replace the loose check with a strict
existence/emptiness check (only return when $value === null or $value === '') so
numeric zero and the string '0' remain visible.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f2ab032 and 83057e9.

📒 Files selected for processing (2)
  • classes/helpers/FrmListHelper.php
  • stripe/helpers/FrmTransLiteAppHelper.php
✅ Files skipped from review due to trivial changes (1)
  • classes/helpers/FrmListHelper.php

Comment on lines +392 to 394
if ( ! $value ) {
return;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

cat -n stripe/helpers/FrmTransLiteAppHelper.php | sed -n '380,410p'

Repository: Strategy11/formidable-forms

Length of output: 896


🏁 Script executed:

rg -nP --type=php -C5 'show_in_table' stripe/

Repository: Strategy11/formidable-forms

Length of output: 2314


🏁 Script executed:

rg -nP --type=php -B10 -A15 'function show_in_table' stripe/

Repository: Strategy11/formidable-forms

Length of output: 1710


Guard clause suppresses legitimate 0 and '0' values.

The condition if ( ! $value ) at line 392 treats 0 and '0' as falsy, causing valid zero values to be hidden. This affects calls like show_in_table( $subscription->fail_count, ... ) at stripe/views/subscriptions/show.php:78, where a "Fail Count" of 0 is meaningful data that should display.

Proposed fix
-		if ( ! $value ) {
+		if ( '' === $value || null === $value ) {
 			return;
 		}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@stripe/helpers/FrmTransLiteAppHelper.php` around lines 392 - 394, The guard
clause currently uses a loose falsy check on $value which hides legitimate 0 and
'0' values; update the guard in FrmTransLiteAppHelper.php to only return for
truly absent values (e.g. null or empty string) rather than any falsy value so
calls like show_in_table($subscription->fail_count, ...) will display 0; locate
the block using the $value variable and replace the loose check with a strict
existence/emptiness check (only return when $value === null or $value === '') so
numeric zero and the string '0' remain visible.

@Crabcyborg
Crabcyborg merged commit f6f0cf5 into master Feb 26, 2026
19 of 21 checks passed
@Crabcyborg
Crabcyborg deleted the enforce_more_early_exits branch February 26, 2026 18:19
stephywells pushed a commit that referenced this pull request Apr 4, 2026
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