Skip to content

[CodeQuality] Skip assertNull/assertEmpty in AssertEmptyNullableObjectToAssertInstanceofRector - #780

Merged
TomasVotruba merged 1 commit into
mainfrom
fix-assert-null-widening-9867
Sep 2, 2026
Merged

[CodeQuality] Skip assertNull/assertEmpty in AssertEmptyNullableObjectToAssertInstanceofRector#780
TomasVotruba merged 1 commit into
mainfrom
fix-assert-null-widening-9867

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Sep 2, 2026

Copy link
Copy Markdown
Member

Fixes rectorphp/rector#9867

The rule converted assertNull()/assertEmpty() on a nullable object into assertNotInstanceOf(SomeClass::class, ...).

For a SomeClass|null union that is logically equivalent, but assertNotInstanceOf is no clearer than the original assertNull - the opposite of the rule's stated goal ("Change assertNotEmpty() and assertNotNull() on an object to more clear assertInstanceof()"). The rule name and its only code sample also cover just the not-empty/not-null direction.

This keeps only the useful narrowing:

  • assertNotEmpty / assertNotNull -> assertInstanceOf

and leaves assertNull / assertEmpty untouched.

…tToAssertInstanceofRector

assertNull/assertEmpty were converted to assertNotInstanceOf, which is no
clearer than the original and contradicts the rule's stated goal of narrowing
to assertInstanceOf. Keep only the assertNotEmpty/assertNotNull direction.

Fixes #9867

Claude-Session: https://claude.ai/code/session_013HSzJq1AksJfqCvf2bX1nk
@TomasVotruba
TomasVotruba merged commit 126d4a6 into main Sep 2, 2026
7 checks passed
@TomasVotruba
TomasVotruba deleted the fix-assert-null-widening-9867 branch September 2, 2026 08:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

AssertEmptyNullableObjectToAssertInstanceofRector phpunit rule converting assertNull into assertInstanceOf, which isn't more narrow

1 participant