Skip to content

Apply slevomat early exits#2948

Merged
Crabcyborg merged 5 commits into
masterfrom
apply_slevomat_early_exits
Feb 6, 2026
Merged

Apply slevomat early exits#2948
Crabcyborg merged 5 commits into
masterfrom
apply_slevomat_early_exits

Conversation

@Crabcyborg
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg commented Feb 6, 2026

Summary by CodeRabbit

  • Refactor
    • Streamlined internal control flow across the app with consistent early-return guards and inverted conditionals to reduce nesting and improve reliability; no change to user-facing behavior.
    • Tightened defensive checks to avoid unnecessary processing and potential edge-case errors during form operations and imports.
  • Style
    • Added a coding-standard rule to promote early-exit patterns for clearer, more maintainable code.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 6, 2026

📝 Walkthrough

Walkthrough

This PR consistently converts nested conditionals into early-return/guard clauses across controllers, helpers, models, integrations, tests, and config—reordering checks so methods exit immediately when prerequisites are missing and proceed only when required conditions are met.

Changes

Cohort / File(s) Summary
Controllers
classes/controllers/FrmAddonsController.php, classes/controllers/FrmAppController.php, classes/controllers/FrmDashboardController.php, classes/controllers/FrmEntriesController.php, classes/controllers/FrmFieldsController.php, classes/controllers/FrmFormTemplatesController.php, classes/controllers/FrmFormsController.php, classes/controllers/FrmOnboardingWizardController.php, classes/controllers/FrmStylesController.php
Refactored to use early-return guards for page/context checks, permission and capability checks, enqueue/register logic, redirect and action flows; methods now exit early when prerequisites are not met.
Core Helpers
classes/helpers/FrmAppHelper.php, classes/helpers/FrmEntriesHelper.php, classes/helpers/FrmFieldGridHelper.php, classes/helpers/FrmFieldsHelper.php, classes/helpers/FrmFormsListHelper.php
Inverted conditionals to short-circuit on missing data or disabled behaviors; moved validation/processing blocks behind guards (permission handling, "other" value processing, parent-list sync, table-nav rendering).
XML & Data Helpers
classes/helpers/FrmXMLHelper.php
Widespread early-exit refactors across import/parse/migration helpers: many methods now return when inputs/mappings are absent, and proceed only when required form/field mappings or settings exist.
Models — Core
classes/models/FrmAddon.php, classes/models/FrmCreateFile.php, classes/models/FrmDb.php, classes/models/FrmEmail.php, classes/models/FrmEntry.php, classes/models/FrmEntryMeta.php, classes/models/FrmForm.php, classes/models/FrmFormMigrator.php, classes/models/FrmInbox.php, classes/models/FrmInstallerSkin.php, classes/models/FrmMigrate.php, classes/models/FrmSettings.php, classes/models/FrmSpamCheckDenylist.php
Added guard clauses for license/cache/timeout handling, filesystem/permission checks, option conversion, message cleanup, and migration flows; skip work when environment or inputs are missing.
Validation & Field Core
classes/models/FrmEntryValidate.php, classes/models/FrmField.php
Refactored validation gates and transient handling to return early when requirements fail (Akismet skipping, phone validation, option matching, default/unserialize handling).
Field Models
classes/models/fields/FrmFieldCombo.php, classes/models/fields/FrmFieldFormHtml.php, classes/models/fields/FrmFieldName.php, classes/models/fields/FrmFieldType.php, classes/models/FrmFieldValueSelector.php
Guarded against empty attrs, non-string inner HTML, missing DB rows, and disabled style usage; initialization and attribute rendering now early-exit when not applicable.
Integrations & Autoloader
formidable.php, square/controllers/FrmSquareLiteAppController.php, stripe/controllers/FrmTransLiteActionsController.php, stripe/models/FrmStrpLiteAuth.php
Inverted guards in autoloader and integration controllers/models to skip processing on absent inputs (class type, item_meta, descriptions, actions), preventing unnecessary work and undefined access.
Tests & Config
tests/phpunit/base/FrmUnitTest.php, tests/phpunit/fields/test_FrmFieldValidate.php, tests/phpunit/form-templates/test_FrmFormTemplatesController.php, phpcs.xml
Unit tests made more defensive with early-return/continue for missing files/params; added SlevomatCodingStandard.ControlStructures.EarlyExit rule to phpcs.xml to relax early-exit checks.
Other Models & Fields
classes/models/FrmSolution.php, classes/models/FrmFieldFormHtml.php, classes/models/FrmFieldValueSelector.php, classes/models/FrmFieldValueSelector.php
Minor control-flow inversions to early-return on non-applicable states for settings rendering, HTML id insertion, and value-selector initialization.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰
I hop through nested ifs with glee,
Guard clauses tidy up the tree.
One quick return, the branches part,
A tidy codebase — carrot heart. 🥕

🚥 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 'Apply slevomat early exits' clearly and specifically describes the main change: refactoring code to apply early exit patterns as per the Slevomat coding standard rule.
Docstring Coverage ✅ Passed Docstring coverage is 95.06% 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
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch apply_slevomat_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
Copy link
Copy Markdown

deepsource-io Bot commented Feb 6, 2026

Here's the code health analysis summary for commits cf4606a..16126df. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource PHP LogoPHP❌ Failure
❗ 19 occurences introduced
View Check ↗
DeepSource JavaScript LogoJavaScript✅ SuccessView Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
classes/models/FrmEntryValidate.php (1)

281-281: ⚠️ Potential issue | 🟡 Minor

Pipeline failure: trim() receives mixed|numeric instead of string.

Psalm flags $current_value as mixed|numeric because it comes from iterating over (array) $value (line 263), whose elements aren't guaranteed to be strings. This also affects line 287 and the call on line 293.

Casting to string at the start of the inner loop iteration would resolve this across all downstream trim() calls:

Proposed fix
 		foreach ( $value as $current_value ) {
+			$current_value = (string) $current_value;
 			$match = false;
tests/phpunit/base/FrmUnitTest.php (1)

453-468: ⚠️ Potential issue | 🟡 Minor

Reset $frm_vars even when FrmProEddController is absent.
The early return skips clearing plugin globals, which can leak state between tests if the class isn’t loaded.

🔧 Suggested fix
-		if ( ! class_exists( 'FrmProEddController' ) ) {
-			return;
-		}
-
-		$frm_vars = array(
+		$frm_vars = array(
 			'load_css'          => false,
 			'forms_loaded'      => array(),
 			'created_entries'   => array(),
 			'pro_is_authorized' => false,
 			'next_page'         => array(),
 			'prev_page'         => array(),
 		);
 
+		if ( ! class_exists( 'FrmProEddController' ) ) {
+			return;
+		}
+
 		$frmedd_update                 = new FrmProEddController();
 		$frm_vars['pro_is_authorized'] = $frmedd_update->pro_is_authorized();
🤖 Fix all issues with AI agents
In `@classes/controllers/FrmAddonsController.php`:
- Around line 665-679: Guard against missing entries in the API response by
checking isset($addon_info[$download_id]) before using it: when calling
$api->get_api_info() (addon_info) verify the download key exists prior to
assigning to $version_info[$download_id] and prior to reading
$addon_info['error']; if the key is absent, skip assignment or set a safe
default (e.g., an error entry) so that references to $version_info[$download_id]
and accesses in subsequent code (the block that sets ['error'] from
$addon_info['error']) do not trigger undefined index notices.

In `@phpcs.xml`:
- Around line 170-176: The PHPCS rule block for
SlevomatCodingStandard.ControlStructures.EarlyExit contains an unsupported
property; remove the property named ignoreTrailingIfWithOneInstruction and leave
only the two valid properties ignoreStandaloneIfInScope and
ignoreOneLineTrailingIf within the <rule
ref="SlevomatCodingStandard.ControlStructures.EarlyExit"> block to match the
supported sniff configuration.
🧹 Nitpick comments (2)
classes/models/FrmAddon.php (1)

346-353: Early return is correct; minor nit on the redundant reset.

The guard clause correctly mirrors the original nested logic. One observation: Line 353 ($this->should_clear_cache = true) is only reachable when $this->should_clear_cache is already true, making the assignment a no-op. Consider removing it or, if the intent is to reset state after an external caller sets it false, note that the early return on Line 346 prevents that reset from ever firing in that scenario.

This is pre-existing, not introduced by this PR — just flagging since you're touching this block.

classes/models/fields/FrmFieldName.php (1)

231-233: $hidden_field is unused in the foreach loop.

Static analysis flags $hidden_field as unused — only $name is referenced in the loop body. This is pre-existing (not introduced by this PR), but since you're touching these lines, consider using $_ or just the key.

♻️ Optional fix
-		foreach ( $hidden_fields as $name => $hidden_field ) {
+		foreach ( array_keys( $hidden_fields ) as $name ) {
 			$args['sub_fields'][ $name ]['wrapper_classes'] .= ' frm_hidden';
 		}

Comment thread classes/controllers/FrmAddonsController.php
Comment thread phpcs.xml
@Crabcyborg Crabcyborg merged commit 0e1d7b3 into master Feb 6, 2026
17 of 20 checks passed
@Crabcyborg Crabcyborg deleted the apply_slevomat_early_exits branch February 6, 2026 18:58
@coderabbitai coderabbitai Bot mentioned this pull request Feb 26, 2026
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