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

Add rule to check for checking value in `match` or `switch` instruction

Open jdecool opened this issue 3 years ago • 0 comments

Example:

/**
 * @extends Enum<int>
 */
class MyEnum extends Enum
{
    public const FOO = 1;
    public const BAR = 2;

    public function getLabel(): string {
        return match ($this->value) {
            self::FOO => 'foo-value',
            self::BAR => 'bar-value',
        };
    }
}

Will output errors because it phpstan consider that values from ]-ING;0] and [3;+INF] are not checked.

jdecool avatar Oct 10 '22 21:10 jdecool