1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

Fix @no-named-arguments more

This commit is contained in:
Matt Brown 2020-10-02 21:09:37 -04:00
parent 1839b3e701
commit 6a91c2f70e
2 changed files with 34 additions and 2 deletions

View File

@ -533,7 +533,7 @@ class ArgumentsAnalyzer
foreach ($args as $argument_offset => $arg) {
$function_param = null;
if ($arg->name) {
if ($arg->name && $function_storage->allow_named_arg_calls) {
foreach ($function_params as $candidate_param) {
if ($candidate_param->name === $arg->name->name) {
$function_param = $candidate_param;
@ -622,7 +622,7 @@ class ArgumentsAnalyzer
foreach ($args as $argument_offset => $arg) {
$function_param = null;
if ($arg->name) {
if ($arg->name && $function_storage && $function_storage->allow_named_arg_calls) {
foreach ($function_params as $candidate_param) {
if ($candidate_param->name === $arg->name->name) {
$function_param = $candidate_param;

View File

@ -247,6 +247,38 @@ class ArgTest extends TestCase
}',
'error_message' => 'InvalidNamedArgument'
],
'noNamedArgsMethod' => [
'<?php
class CustomerData
{
/** @no-named-arguments */
public function __construct(
public string $name,
public string $email,
public int $age,
) {}
}
/**
* @param array{age: int, name: string, email: string} $input
*/
function foo(array $input) : CustomerData {
return new CustomerData(
age: $input["age"],
name: $input["name"],
email: $input["email"],
);
}',
'error_message' => 'InvalidScalarArgument'
],
'noNamedArgsFunction' => [
'<?php
/** @no-named-arguments */
function takesArguments(string $name, int $age) : void {}
takesArguments(age: 5, name: "hello");',
'error_message' => 'InvalidScalarArgument'
],
];
}
}