Skip to content

False positive on Assert::upper() always evaluates as true #85

@p4veI

Description

@p4veI

Hello I just updated phpstan-webmozart-assert to v1.0.7 and my codebase started reporting this error:

Call to static method Webmozart\Assert\Assert::upper() with non-empty-string will always evaluate to true.

It's failing in the following class construct

final class CityCode
{
    private function __construct(private string $cityCode)
    {
    }

    public static function fromString(string $cityCode) : self
    {
        Assert::length($cityCode, 3);
        Assert::upper($cityCode);

        return new self($cityCode);
    }
}

I'm not using the non-empty-string type assertion anywhere so it must be resolved from the length assertion, however that doesn't ensure what upper is doing.

Thank you for looking into this, and all your great work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions