phpstan/phpstan-webmozart-assert

Since 0.12.9: `expects array<string>, iterable<string> given`

ruudk opened this issue · 4 comments

ruudk commented

Not sure if this is an issue or not, and if it's related to phpstan-webmozart-assert or just webmozart-assert.

When upgrading from 0.12.8 to 0.12.9 I get this error:

Parameter #1 $input of class Command constructor expects array<string>, iterable<string> given.

This is coming from:

$input = $request->request->get('input');

Assert::isList($input);
Assert::allString($input);

$command = new Command($input)

My Command has the following constructor:

/**
* @param string[] $input
*/
public function __construct(array $input)

Assert's allString method defines:

    /**
     * @psalm-pure
     * @psalm-assert iterable<string> $value
     *
     * @param mixed  $value
     * @param string $message
     *
     * @throws InvalidArgumentException
     */
    public static function allString($value, $message = '');

It seems that PHPStan no longer accepts passing an iterable<string> into a string[].

This is actually a feature request for isList assert to be supported. Implemented: 7c19228

0.12.10 released.

ruudk commented

@ondrejmirtes Amazing, thank you!! 💙

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.