Skip to content

@no-named-arguments leads to static analysis errors for variadic arguments #6163

Open
@m-vo

Description

@m-vo
Q A
PHPUnit version at least version 9

Summary

The InvocationMocker class is annotated with @no-named-arguments - as this is on a class-level, it also affects the with() function, that only has a single variadic argument. This leads to static analysis issues.

Current behavior

When using PHPStan in a project where with() is used with an array (not a list), this may lead to a static analysis error (although the keys are ignored anyways):

 Method […]\InvocationMocker::willReturn() invoked with unpacked array with possibly string key, but it's not allowed because of @no-named-arguments.

How to reproduce

$input = ['a' => 'foo', 'b' => 'bar'];

$mock->with(...$input); // invalid
$mock->with(...array_values($input)); // valid

$mock->willReturn(/* … */);

Expected behavior

Both cases are a valid usage, so I'd expect there would be no static analysis errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bugSomething is broken

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions