phpstan-src icon indicating copy to clipboard operation
phpstan-src copied to clipboard

Fix strtr inferences

Open VincentLanglet opened this issue 4 months ago • 5 comments

Closes https://github.com/phpstan/phpstan/issues/13708

VincentLanglet avatar Oct 21 '25 09:10 VincentLanglet

Escaped mutants here. This means tests need to be written so that when the code changes like that, there will be some tests that will fail. Possibly the code logic might be wrong too.

ondrejmirtes avatar Dec 05 '25 08:12 ondrejmirtes

Escaped mutants here. This means tests need to be written so that when the code changes like that, there will be some tests that will fail. Possibly the code logic might be wrong too.

I'm not sure what should be expected here.

The mutant can only occurs if we pass string|array as second param and wether it infers non-empty-string or not seems kinda useless to me because it's already reported as an error by PHPStan which should be fixed first https://phpstan.org/r/1b1f1f8a-dbd4-417c-b251-be553d4d64d3.

Also if I try to support "maybe array" with something like

TypeCombinator::intersect(new ArrayType(new MixedType(), new MixedType()), $secondArgumentType)

I'll still get "false positive" escaped mutant because now $type->isArray()->maybe() will be useless and therefor ->yes() or ! -> no() are equivalent.

VincentLanglet avatar Dec 05 '25 09:12 VincentLanglet

Maybe array is also for example mixed or array|null.

kinda useless to me because it's already reported as an error by PHPStan

Type inference and error reporting are two independent different parts of PHPStan. Type inference should still do something sensible even if the user passes a wrong type there. Especially when the wrong type might not even be reported on a lower rule level.

ondrejmirtes avatar Dec 05 '25 09:12 ondrejmirtes

No mutant escaped now @ondrejmirtes :)

The lint 8.0 failure seems unrelated/random

VincentLanglet avatar Dec 05 '25 10:12 VincentLanglet

No mutant escaped now @ondrejmirtes :)

The lint 8.0 failure seems unrelated/random

I also rebased and fixed all my existing PR if you have time for a look https://github.com/phpstan/phpstan-src/pulls/VincentLanglet. I commented those with failing build, some failure are unrelated/random ; and some mutant are (I think) not fixable.

VincentLanglet avatar Dec 05 '25 16:12 VincentLanglet