Skip to content

Update sniff to catch more variables declared before returns where th…#2824

Closed
Crabcyborg wants to merge 1 commit into
masterfrom
update_sniff_to_catch_more_variables_declared_before_returns_where_they_are_unused
Closed

Update sniff to catch more variables declared before returns where th…#2824
Crabcyborg wants to merge 1 commit into
masterfrom
update_sniff_to_catch_more_variables_declared_before_returns_where_they_are_unused

Conversation

@Crabcyborg
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg commented Jan 16, 2026

…ey are unused

Summary by CodeRabbit

  • Refactor

    • Reorganized variable initialization and control flow ordering across multiple helper and model classes for improved code structure and maintainability.
  • Chores

    • Enhanced code quality tooling with a new PHP code sniffer to detect and suggest improvements for variable declaration placement relative to early returns.

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 16, 2026

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This PR systematically relocates variable initializations throughout the codebase to occur after early returns, guards, or checks. It also significantly enhances a PHPCS sniff to detect and enforce this pattern across multiple early-return blocks, enabling automated code quality improvements.

Changes

Cohort / File(s) Change Summary
PHPCS Sniff Enhancement
phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/MoveVariableBelowEarlyReturnSniff.php
Reworked to detect multiple early-return blocks and added three new private methods (findEarlyReturns, checkVariablesBeforeEarlyReturn, isVariableAssignedInRange) to analyze variable usage patterns and move declarations conditionally. Enhanced applyFix to preserve comments and handle proper placement relative to early-return blocks.
Controller Variable Reordering
classes/controllers/FrmAddonsController.php, FrmAppController.php, FrmFormActionsController.php, FrmWelcomeTourController.php, stripe/controllers/FrmStrpLiteActionsController.php, FrmStrpLiteAppController.php
Moved variable initializations ($plugin, $page, $post_type, $view_path, $all_instances, $entry) to occur after early returns or conditional checks, deferring computation until needed. Some changes may introduce undefined variable risks if later code paths are not fully guarded.
Helper Variable Reordering & Guard Strengthening
classes/helpers/FrmAppHelper.php, FrmFieldsHelper.php, FrmFormsHelper.php, FrmListHelper.php, FrmSubmitHelper.php, FrmXMLHelper.php, square/helpers/FrmSquareLiteConnectHelper.php, stripe/helpers/FrmStrpLiteConnectHelper.php
Restructured initialization timing for variables ($len, $pointer, $parent, $caution, $i, $updated, $item_meta, $customer_id) and added early guard clauses. FrmFieldsHelper adds comprehensive nonce/action verification within admin context checks; others defer URL/value retrieval until validation passes.
Model Variable Reordering
classes/models/FrmApplicationTemplate.php, FrmField.php, FrmFormAction.php, FrmFormApi.php, FrmInbox.php, FrmSpamCheckUseWPComments.php, fields/FrmFieldCaptcha.php, fields/FrmFieldName.php, stripe/helpers/FrmStrpLiteConnectApiAdapter.php
Moved variable initializations ($license_type, $new_id, $all_instances, $plugin, $frm_settings, $name_layout, $customer_id) to occur conditionally after checks or API calls, avoiding unnecessary computation on early-return paths.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

🐰 Hop along the code we go,
Variables now know when to show,
After guards and checks so neat,
Our early returns are complete!
The sniff hops twice, thrice, and more,
Code quality opens each door! 🌱✨

✨ Finishing touches
  • 📝 Generate docstrings


📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6de8ab7 and 621bc64.

📒 Files selected for processing (24)
  • classes/controllers/FrmAddonsController.php
  • classes/controllers/FrmAppController.php
  • classes/controllers/FrmFormActionsController.php
  • classes/controllers/FrmWelcomeTourController.php
  • classes/helpers/FrmAppHelper.php
  • classes/helpers/FrmFieldsHelper.php
  • classes/helpers/FrmFormsHelper.php
  • classes/helpers/FrmListHelper.php
  • classes/helpers/FrmSubmitHelper.php
  • classes/helpers/FrmXMLHelper.php
  • classes/models/FrmApplicationTemplate.php
  • classes/models/FrmField.php
  • classes/models/FrmFormAction.php
  • classes/models/FrmFormApi.php
  • classes/models/FrmInbox.php
  • classes/models/FrmSpamCheckUseWPComments.php
  • classes/models/fields/FrmFieldCaptcha.php
  • classes/models/fields/FrmFieldName.php
  • phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/MoveVariableBelowEarlyReturnSniff.php
  • square/helpers/FrmSquareLiteConnectHelper.php
  • stripe/controllers/FrmStrpLiteActionsController.php
  • stripe/controllers/FrmStrpLiteAppController.php
  • stripe/helpers/FrmStrpLiteConnectApiAdapter.php
  • stripe/helpers/FrmStrpLiteConnectHelper.php

✏️ Tip: You can disable this entire section by setting review_details to false in your review 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 closed this Jan 16, 2026
@Crabcyborg Crabcyborg deleted the update_sniff_to_catch_more_variables_declared_before_returns_where_they_are_unused branch January 16, 2026 19:01
@Crabcyborg Crabcyborg removed this from the 6.28 milestone Jan 20, 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