phpstan/phpstan-beberlei-assert

Chainable types do not work

bendavies opened this issue · 0 comments

the following code:

<?php

declare(strict_types=1);

use Assert\Assert;

class Result
{
    private ?float $percent;

    private function __construct()
    {
    }

    /** @param array<string, mixed> $payload */
    public static function fromQueryResults(array $payload): self
    {
        Assert::that($payload['percent'])
            ->nullOr()
            ->string()
            ->numeric();

        $floatOrNull = static fn (?string $value): ?float => null === $value ? null : (float) $value;

        $instance = new self();
        $instance->percent = $floatOrNull($payload['percent']);

        return $instance;
    }
}

Produces the error:
Parameter #1 $value of closure expects string|null, float|int|string|null given.

The type of $payload['percent'] should be infered to string|null, not float|int|string|null