Skip to content

Parameter with integer range in phpdoc raises error during check even with "treatPhpDocTypesAsCertain" set to false #7075

@lcdennison

Description

@lcdennison

Bug report

Using 1.5.7.

I have treatPhpDocTypesAsCertain: false in my phpstan config, and that directive is working in other scenarios. However, when I apply an integer range to a parameter, and then try to check that condition (so I can throw an Exception), phpstan is saying the condition is always false. Simple example:

/**
 * @param int<1,max> $number
 */
function foo(int $number): void {
    if ($number < 1) { // error raised because condition is "always false"
        throw new \Exception('Number cannot be less than 1');
    }
}

Shouldn't this error be suppressed by treatPhpDocTypesAsCertain set to false? Or is there some other way to handle this case?

Code snippet that reproduces the problem

https://phpstan.org/r/be1acdf0-5115-40e8-b235-0fe01c94f075

Expected output

I expect no error to be raised.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions