Skip to content

Fix type safety issues and logic bugs across multiple sniffs#49

Merged
dereuromark merged 1 commit intomasterfrom
bugfix/type-safety-and-logic-fixes
Mar 27, 2026
Merged

Fix type safety issues and logic bugs across multiple sniffs#49
dereuromark merged 1 commit intomasterfrom
bugfix/type-safety-and-logic-fixes

Conversation

@dereuromark
Copy link
Copy Markdown
Contributor

Summary

  • Fix several type safety issues and logic bugs discovered during code review
  • Add test coverage for NoIsNullSniff

Changes

Bug Fixes

File Issue
AbstractSniff.php array_search('src', ...) returning 0 was treated as falsy, incorrectly triggering the 'tests' fallback
EnumCaseCasingSniff.php ucfirst() after mb_strtolower() - now uses mb_strtoupper(mb_substr(...)) for proper multibyte support
NoIsNullSniff.php Line 103 called wrong method (findUnnecessaryLeadingComparisonStart instead of findUnnecessaryTrailingComparisonEnd)
NoIsNullSniff.php findUnnecessaryTrailingComparisonEnd() now properly handles !== comparisons (e.g., is_null($x) !== true)
Multiple sniffs (int) casting of findNext()/findPrevious() masked false returns - now uses proper === false checks

Affected Sniffs

  • AbstractSniff
  • EnumCaseCasingSniff
  • NoInlineAssignmentSniff
  • NoIsNullSniff
  • PhpSapiConstantSniff
  • PreferCastOverFunctionSniff

New Tests

  • Added NoIsNullSniffTest with 8 test cases covering:
    • Basic is_null()=== null
    • Negated !is_null()!== null
    • Leading comparisons: true === is_null(), false === is_null()
    • Trailing comparisons: is_null() === true/false, is_null() !== true/false

- AbstractSniff: Fix array_search() returning 0 being treated as false
- EnumCaseCasingSniff: Use mb_strtoupper/mb_substr for proper multibyte support
- NoIsNullSniff: Fix wrong method call and add support for !== comparisons
- NoInlineAssignmentSniff, PhpSapiConstantSniff, PreferCastOverFunctionSniff:
  Replace (int) casting of findNext/findPrevious with proper === false checks

Add test coverage for NoIsNullSniff including trailing comparison cases.
@dereuromark dereuromark merged commit 06a75d0 into master Mar 27, 2026
4 checks passed
@dereuromark dereuromark deleted the bugfix/type-safety-and-logic-fixes branch March 27, 2026 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant