Skip to content

Update redundant empty on param sniff to catch boolean assignemnts an…#2858

Merged
Crabcyborg merged 1 commit into
masterfrom
update_redundant_empty_on_param_sniff_to_catch_boolean_assignments
Jan 22, 2026
Merged

Update redundant empty on param sniff to catch boolean assignemnts an…#2858
Crabcyborg merged 1 commit into
masterfrom
update_redundant_empty_on_param_sniff_to_catch_boolean_assignments

Conversation

@Crabcyborg
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg commented Jan 22, 2026

…d ternaries

Summary by CodeRabbit

  • Refactor

    • Improved conditional logic evaluation throughout the codebase for better consistency and clarity.
  • Chores

    • Enhanced code analysis tool to better detect redundant conditions in boolean contexts, improving code quality insights for developers.

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 22, 2026

📝 Walkthrough

Walkthrough

This PR simplifies conditional logic across multiple helper and model files by replacing explicit empty() checks with direct truthiness checks (e.g., empty($to)! $to), and enhances the RedundantEmptyOnParameterSniff PHPCS rule to better detect boolean contexts, including adjacent logical operators.

Changes

Cohort / File(s) Summary
Code Simplification
classes/helpers/FrmAppHelper.php, classes/helpers/FrmFormMigratorsHelper.php, classes/models/FrmField.php, classes/models/FrmMigrate.php
Replaced empty() checks with simpler truthiness operators (! $var or direct $var), altering evaluation for falsy values like 0, '', and null
Sniff Enhancement
phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/RedundantEmptyOnParameterSniff.php
Renamed isInIfCondition() to isInBooleanContext(), added hasAdjacentLogicalOperator() helper to detect logical operators (||, &&) surrounding empty() calls, and enhanced boolean-context detection to short-circuit when adjacent operators are present

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Empty checks we simplify, with truthiness held high,
The sniff grows wise to context near, detecting && and ||,
No more redundant calls to keep, just clean and honest checks so deep!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'Update redundant empty on param sniff to catch boolean assignemnts an…' accurately describes the main change in the pull request - expanding the sniff to detect additional boolean contexts. However, the title contains a typo ('assignemnts' instead of 'assignments') and is truncated, making it incomplete. Clarify the complete title by fixing the typo and completing the truncated portion (appears to end with 'and...' suggesting content about ternaries is cut off).
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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 docstrings

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 merged commit f8344bd into master Jan 22, 2026
35 of 38 checks passed
@Crabcyborg Crabcyborg deleted the update_redundant_empty_on_param_sniff_to_catch_boolean_assignments branch January 22, 2026 00:48
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: 1

🤖 Fix all issues with AI agents
In
`@phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/RedundantEmptyOnParameterSniff.php`:
- Around line 54-56: The current boolean-context guard (call to
isInBooleanContext in RedundantEmptyOnParameterSniff) skips cases like
assignments and ternaries (e.g., "$flag = empty($param);" or "empty($param) ?
'a' : 'b'"); update isInBooleanContext to also detect assignment operators ('=')
and ternary tokens ('?' / ':') as valid boolean contexts (or remove the guard
entirely to always check parameter-only empty() usage), then adjust the earlier
return that uses isInBooleanContext to allow these cases; apply the same change
to the other occurrences in the file (the logic used between the ranges
referenced around lines 229-369) so assignments and ternaries are flagged too.

Comment on lines +54 to 56
// Only process if empty() is in a boolean context (if/elseif condition or with || / &&).
if ( ! $this->isInBooleanContext( $phpcsFile, $stackPtr ) ) {
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

Boolean-context gate still misses plain assignments/ternaries.

The new logic only returns true for if/elseif or when empty() is adjacent to &&/||. Cases like $flag = empty( $param ); or empty( $param ) ? 'yes' : 'no' won’t be flagged, which conflicts with the PR intent to catch boolean assignments/ternaries. Consider broadening isInBooleanContext to cover ternary/assignment usage or dropping the boolean-context guard for parameter-only empty().

Also applies to: 229-369

🤖 Prompt for AI Agents
In
`@phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/RedundantEmptyOnParameterSniff.php`
around lines 54 - 56, The current boolean-context guard (call to
isInBooleanContext in RedundantEmptyOnParameterSniff) skips cases like
assignments and ternaries (e.g., "$flag = empty($param);" or "empty($param) ?
'a' : 'b'"); update isInBooleanContext to also detect assignment operators ('=')
and ternary tokens ('?' / ':') as valid boolean contexts (or remove the guard
entirely to always check parameter-only empty() usage), then adjust the earlier
return that uses isInBooleanContext to allow these cases; apply the same change
to the other occurrences in the file (the logic used between the ranges
referenced around lines 229-369) so assignments and ternaries are flagged too.

stephywells pushed a commit that referenced this pull request Apr 4, 2026
…ram_sniff_to_catch_boolean_assignments

Update redundant empty on param sniff to catch boolean assignemnts an…
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