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

Issue with MathUtilityTypeSpecifyingExtension

Open alexanderschnitzler opened this issue 6 months ago • 3 comments

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.      
 ------ ------------------------------------------------------------------------------

alexanderschnitzler avatar May 19 '25 09:05 alexanderschnitzler

Your are mixing different variables: $value and $this->value

sascha-egerer avatar May 19 '25 10:05 sascha-egerer

Your are mixing different variables: $value and $this->value

True, it's a copy paste error. The issue remains.

alexanderschnitzler avatar May 19 '25 10:05 alexanderschnitzler

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.

sascha-egerer avatar Jul 29 '25 20:07 sascha-egerer