Skip to content

Update sniff to catch more redundant parentheses#2891

Merged
Crabcyborg merged 1 commit into
masterfrom
update_sniff_to_catch_more_redundant_parentheses
Jan 27, 2026
Merged

Update sniff to catch more redundant parentheses#2891
Crabcyborg merged 1 commit into
masterfrom
update_sniff_to_catch_more_redundant_parentheses

Conversation

@Crabcyborg
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg commented Jan 27, 2026

Summary by CodeRabbit

  • New Features

    • Enhanced code analysis to detect redundant parentheses in logical expressions with improved accuracy.
  • Chores

    • Reorganized code style rule categorization for better structure.

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 27, 2026

📝 Walkthrough

Walkthrough

Added new detection logic to identify redundant parentheses around simple comparisons within logical expressions in RedundantParenthesesSniff. Extended the existing simple comparison detector to reject expressions containing arithmetic operators. Relocated a rule from CodeAnalysis to Commenting category in the ruleset configuration.

Changes

Cohort / File(s) Summary
Redundant Parentheses Detection Logic
phpcs-sniffs/Formidable/Sniffs/CodeAnalysis/RedundantParenthesesSniff.php
Added private method isRedundantComparisonInLogicalExpression to validate token context (logical operators, parentheses) around comparisons. Extended isSimpleComparisonExpression with arithmetic operator counting; now rejects expressions with arithmetic tokens. Introduced token groups for comparisons and arithmetic operators.
Ruleset Organization
phpcs-sniffs/Formidable/ruleset.xml
Moved rule Formidable.Commenting.AlignFilterParamTypesWithFunction from CodeAnalysis section to Commenting section.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Parentheses once nested deep,
Now unwrapped from logical sleep,
Arithmetic operators banned,
Comparisons cleaner, neatly planned!
Hopping through code, so refined,
Redundancy left far behind! ✨

🚥 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 accurately describes the main change: enhancing a PHPCS sniff to detect additional cases of redundant parentheses, particularly in logical expressions.
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 078c62e into master Jan 27, 2026
37 of 38 checks passed
@Crabcyborg Crabcyborg deleted the update_sniff_to_catch_more_redundant_parentheses branch January 27, 2026 15:24
stephywells pushed a commit that referenced this pull request Apr 4, 2026
…edundant_parentheses

Update sniff to catch more redundant parentheses
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