Skip to content

New sniff to remove more redundant uses of empty#3005

Merged
Crabcyborg merged 2 commits into
masterfrom
new_sniff_to_remove_more_redundant_uses_of_empty
Mar 6, 2026
Merged

New sniff to remove more redundant uses of empty#3005
Crabcyborg merged 2 commits into
masterfrom
new_sniff_to_remove_more_redundant_uses_of_empty

Conversation

@Crabcyborg
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg commented Mar 6, 2026

Summary by CodeRabbit

Release Notes

  • Refactor

    • Simplified internal null/empty checks throughout the codebase by replacing empty() utility function calls with direct PHP truthiness evaluation for improved code consistency.
  • New Features

    • Added a new code quality rule to the development linter that detects and prevents redundant empty checks on static properties, helping maintain cleaner code patterns.
  • Chores

    • Updated development ruleset to enforce the new code quality rule.

@Crabcyborg Crabcyborg added this to the 6.29 milestone Mar 6, 2026
@Crabcyborg Crabcyborg changed the title New sniff to remove more redundant uses of emptyg New sniff to remove more redundant uses of empty Mar 6, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 6, 2026

Warning

Rate limit exceeded

@Crabcyborg has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 3 minutes and 41 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.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2794bb79-7f0e-4af5-aae8-e69b5c24ba00

📥 Commits

Reviewing files that changed from the base of the PR and between 9d1c200 and 35c1003.

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

Walkthrough

This PR introduces a new PHP_CodeSniffer sniff to detect and auto-fix redundant empty() usage on static properties, then applies this pattern across multiple controller, model, and helper files by converting empty(self::$property) checks to simpler !self::$property boolean tests.

Changes

Cohort / File(s) Summary
Controller & Model Property Checks
classes/controllers/FrmAddonsController.php, classes/controllers/FrmFormTemplatesController.php, classes/models/FrmFormState.php, stripe/helpers/FrmStrpLiteConnectHelper.php
Replaced empty() checks on static properties with truthiness checks using ! operator. Functionally equivalent under normal conditions.
FrmInbox Banner Check
classes/models/FrmInbox.php
Changed from if (empty(self::$banner_messages)) to if (!self::$banner_messages). This alters the early-return behavior and may cause subsequent operations like end() to execute on empty/falsy values, potentially introducing runtime warnings.
FrmSalesApi Redirect Logic
classes/models/FrmSalesApi.php
Simplified !empty(self::$cross_sell_link) to direct truthiness check self::$cross_sell_link, relaxing reliance on empty() helper.
New Static Property Emptiness Sniff
phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/RedundantEmptyOnStaticPropertySniff.php
Introduces 511-line sniff to detect redundant empty() calls on defined static properties and suggest replacement with !property or property. Includes token-level analysis, boolean context detection, and auto-fix capabilities with helper methods for class location, property definition verification, and negation handling.
Sniff Documentation & Ruleset Updates
phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/PreferNotEmptyTernarySniff.php, phpcs-sniffs/Formidable/ruleset.xml
Updated PreferNotEmptyTernary sniff documentation to clarify ternary transformation pattern. Registered new RedundantEmptyOnStaticProperty rule in the Formidable coding standards ruleset.

Possibly related PRs

Poem

🐰 Hops through the code with sniff so keen,
Catching empty() where properties are seen,
A truthiness test, so simple and pure,
The static checks, now lean and sure!
From empty to bang—efficiency's gleam!

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

🚥 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 pull request title accurately summarizes the main change: introducing a new PHP_CodeSniffer sniff to detect and remove redundant empty() usage on static properties.
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.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch new_sniff_to_remove_more_redundant_uses_of_empty

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 Mar 6, 2026

DeepSource Code Review

We reviewed changes in eda915c...9d1c200 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 Mar 6, 2026 9:39p.m. Review ↗
JavaScript Mar 6, 2026 9:39p.m. Review ↗

@deepsource-io
Copy link
Copy Markdown

deepsource-io Bot commented Mar 6, 2026

DeepSource Code Review

We reviewed changes in eda915c...35c1003 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  

Feedback

  • Implicit constant visibility is copy-pasted
    • Multiple files declare REQUIRED_CAPABILITY without an explicit visibility because developers copy existing code; make those constants explicit (public/protected/private) and update any snippets so the omission stops propagating.
  • Controller-level permissions duplicated across classes
    • Each controller defines its own REQUIRED_CAPABILITY, duplicating intent and risking inconsistent access scope; centralize capability declarations (base controller constant, permission enum, or auth mapping) so one explicit visibility and semantics apply.
  • Generators omit visibility in produced code
    • Project scaffolding or templates likely emit class constants without visibility, seeding the same hygiene defect across new files; update generators/snippets to always include explicit visibility so the pattern is broken at source.

Code Review Summary

Analyzer Status Updated (UTC) Details
PHP Mar 6, 2026 9:42p.m. Review ↗
JavaScript Mar 6, 2026 9:42p.m. Review ↗

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

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

Inline comments:
In
`@phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/RedundantEmptyOnStaticPropertySniff.php`:
- Line 189: The phpdoc return type ordering must be changed to satisfy
phpdoc_types_order: update the return annotation that currently reads
"false|array{accessor: string, property: string}" to "array{accessor: string,
property: string}|false" in the docblock for the method that returns the static
access info in RedundantEmptyOnStaticPropertySniff (the docblock for the method
returning the static access info).
- Line 298: The variable $searchStart in RedundantEmptyOnStaticPropertySniff
(assigned with "$searchStart = $i;") is never used; remove the unused assignment
to eliminate the dead variable—locate the assignment inside the method where $i
is set (the context around the static property scanning logic) and delete the
"$searchStart = $i;" line (or, if the original intent was to use it, replace
other references to use $searchStart consistently), ensuring no other code
depends on that variable.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f135fbf5-d152-4e8d-bdf1-0afe5407f505

📥 Commits

Reviewing files that changed from the base of the PR and between eda915c and 9d1c200.

📒 Files selected for processing (9)
  • classes/controllers/FrmAddonsController.php
  • classes/controllers/FrmFormTemplatesController.php
  • classes/models/FrmFormState.php
  • classes/models/FrmInbox.php
  • classes/models/FrmSalesApi.php
  • phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/PreferNotEmptyTernarySniff.php
  • phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/RedundantEmptyOnStaticPropertySniff.php
  • phpcs-sniffs/Formidable/ruleset.xml
  • stripe/helpers/FrmStrpLiteConnectHelper.php


// Check if this declaration includes 'static'.
$hasStatic = false;
$searchStart = $i;
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

Remove unused variable $searchStart.

Static analysis correctly identifies that $searchStart is assigned but never used.

🧹 Proposed fix
 		// Check if this declaration includes 'static'.
 		$hasStatic   = false;
-		$searchStart = $i;

 		// Look ahead through modifiers to find 'static' and the variable.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$searchStart = $i;
// Check if this declaration includes 'static'.
$hasStatic = false;
// Look ahead through modifiers to find 'static' and the variable.
🧰 Tools
🪛 PHPMD (2.15.0)

[warning] 298-298: Avoid unused local variables such as '$searchStart'. (undefined)

(UnusedLocalVariable)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/RedundantEmptyOnStaticPropertySniff.php`
at line 298, The variable $searchStart in RedundantEmptyOnStaticPropertySniff
(assigned with "$searchStart = $i;") is never used; remove the unused assignment
to eliminate the dead variable—locate the assignment inside the method where $i
is set (the context around the static property scanning logic) and delete the
"$searchStart = $i;" line (or, if the original intent was to use it, replace
other references to use $searchStart consistently), ensuring no other code
depends on that variable.

@Crabcyborg Crabcyborg merged commit 3aa01d8 into master Mar 6, 2026
20 of 21 checks passed
@Crabcyborg Crabcyborg deleted the new_sniff_to_remove_more_redundant_uses_of_empty branch March 6, 2026 21:45
stephywells pushed a commit that referenced this pull request Apr 4, 2026
…undant_uses_of_empty

New sniff to remove more redundant uses of empty
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