Skip to content

Fix conflict between TypeHintSniff and Slevomat null position sniffs#427

Merged
dereuromark merged 2 commits into6.xfrom
fix-void-null-type-order-conflict
Mar 14, 2026
Merged

Fix conflict between TypeHintSniff and Slevomat null position sniffs#427
dereuromark merged 2 commits into6.xfrom
fix-void-null-type-order-conflict

Conversation

@dereuromark
Copy link
Member

Summary

  • Remove NullTypeHintOnLastPosition sniff from ruleset
  • Remove nullPosition="last" property from DNFTypeHintFormat sniff

This fixes the conflict where CakePHP's TypeHintSniff expects void to be last in union types (e.g., int|null|void), but Slevomat sniffs enforced null as last position (expecting int|void|null).

The conflict caused PHPCBF to fail when trying to fix files containing both null and void in union types, as both sniffs would fight each other.

This follows the same approach as php-collective/code-sniffer which also doesn't use these Slevomat sniffs.

Fixes #426

… sniffs

Remove `NullTypeHintOnLastPosition` sniff and `nullPosition` property from
`DNFTypeHintFormat` to avoid conflict with CakePHP's `TypeHintSniff` which
expects `void` to be last in union types (e.g., `int|null|void`).

The Slevomat sniffs enforced `null` as last position, causing an unresolvable
conflict where PHPCBF would fail to fix files containing both `null` and `void`
in union types.

Fixes #426
@ADmad
Copy link
Member

ADmad commented Mar 14, 2026

Would usage like null|int still be flagged after this change?

@dereuromark
Copy link
Member Author

Yes, null|int would still be flagged and fixed to int|null.

CakePHP's own TypeHintSniff already handles this - its $shouldSort array defines the expected type order with null near the end (only void comes after).

The existing test files confirm this behavior:

  • Original: @var null|string|int|float
  • Fixed: @var string|float|int|null

The removed Slevomat sniffs were redundant (and conflicting when void was also present).

@dereuromark dereuromark merged commit a747422 into 6.x Mar 14, 2026
6 checks passed
@dereuromark dereuromark deleted the fix-void-null-type-order-conflict branch March 14, 2026 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants