2.x: Fix negation types for Inspector #860
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As discussed in Slack: https://drupal.slack.com/archives/C033S2JUMLJ/p1744383402099899?thread_ts=1744246451.941499&cid=C033S2JUMLJ, the current Inspector implementation doesn't handle negation at all.
For example:
After passing
Inspector::assertAll(fn (array $i): bool => TRUE, $array);
line, PHPStan would think it is always iterable, even if it is not passed::assertAll()
and the result wasFALSE
. This works fine withassert()
, but breaks under other conditions, for example:This leads to a test failure:
PHPStan thinks it is
iterable
, but if it's not passed the assertion, it is anything else but not iterable (mixed~iterable
).It looks like PHPStan is using the
~
symbol for type negation, likemixed~string
, which reads as: This type is anything (mixed
), but definitely notstring
.This PR fixes the issue, and previous tests pass properly as before. This PR is required for #858 because it is not possible to provide proper test cases for it unless negation is supported.