phpstan-typo3
phpstan-typo3 copied to clipboard
Issue with MathUtilityTypeSpecifyingExtension
Hi folks,
I get the following issue with MathUtilityTypeSpecifyingExtension.
function foo(string $value)
{
// At this point phpstan properly assumes that $value is string
if (MathUtility::canBeInterpretedAsInteger($value)) {
return (int)$value;
}
// At this point phpstan falsely assumes that $value is numeric-string and throws errors in the following match statement.
return match ($value) {
'' => null,
'true' => true,
'false' => false,
default => $value,
};
}
It seems like whenever MathUtility::canBeInterpretedAsInteger() is called on a variable, it's type is changed to numeric-string no matter the outcome.
------ ------------------------------------------------------------------------------
55 Dumped type: string
61 Dumped type: numeric-string
64 Match arm comparison between numeric-string and '' is always false.
65 Match arm comparison between numeric-string and 'true' is always false.
66 Match arm comparison between numeric-string and 'false' is always false.
------ ------------------------------------------------------------------------------
Your are mixing different variables: $value and $this->value
Your are mixing different variables:
$valueand$this->value
True, it's a copy paste error. The issue remains.
I already took a look at MathUtility stuff, but it's too complex for a "short look". If someone would like to take care of it, I would be very thankful.