1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00

Add more information to TooMany/TooFewArguments issues

Fixes #481
This commit is contained in:
Matthew Brown 2018-02-02 11:26:55 -05:00
parent 08c1d65ad2
commit 861d907845
5 changed files with 15 additions and 9 deletions

View File

@ -288,7 +288,7 @@ class FunctionCallChecker extends \Psalm\Checker\Statements\Expression\CallCheck
}
// do this here to allow closure param checks
if (self::checkFunctionArgumentsMatch(
if (self::checkFunctionLikeArgumentsMatch(
$statements_checker,
$stmt->args,
$method_id,

View File

@ -212,7 +212,7 @@ class CallChecker
);
}
if (self::checkFunctionArgumentsMatch(
if (self::checkFunctionLikeArgumentsMatch(
$statements_checker,
$args,
$method_id,
@ -473,7 +473,7 @@ class CallChecker
*
* @return false|null
*/
protected static function checkFunctionArgumentsMatch(
protected static function checkFunctionLikeArgumentsMatch(
StatementsChecker $statements_checker,
array $args,
$method_id,
@ -509,6 +509,8 @@ class CallChecker
if ($method_id && strpos($method_id, '::') && !$in_call_map) {
$cased_method_id = MethodChecker::getCasedMethodId($project_checker, $method_id);
} elseif ($function_storage) {
$cased_method_id = $function_storage->cased_name;
}
if ($method_id && strpos($method_id, '::')) {
@ -769,7 +771,8 @@ class CallChecker
) {
if (IssueBuffer::accepts(
new TooManyArguments(
'Too many arguments for method ' . ($cased_method_id ?: $method_id),
'Too many arguments for method ' . ($cased_method_id ?: $method_id)
. ' - expecting ' . count($function_params) . ' but saw ' . count($args),
$code_location
),
$statements_checker->getSuppressedIssues()
@ -787,7 +790,8 @@ class CallChecker
if (!$param->is_optional && !$param->is_variadic) {
if (IssueBuffer::accepts(
new TooFewArguments(
'Too few arguments for method ' . $cased_method_id,
'Too few arguments for method ' . $cased_method_id
. ' - expecting ' . count($function_params) . ' but saw ' . count($args),
$code_location
),
$statements_checker->getSuppressedIssues()

View File

@ -482,7 +482,8 @@ class AnnotationTest extends TestCase
}
fooBar("hello");',
'error_message' => 'TooManyArguments',
'error_message' => 'TooManyArguments - src/somefile.php:8 - Too many arguments for method fooBar '
. '- expecting 0 but saw 1',
],
'missingParamVar' => [
'<?php

View File

@ -503,7 +503,8 @@ class FunctionCallTest extends TestCase
'<?php
function fooFoo(int $a): void {}
fooFoo(5, "dfd");',
'error_message' => 'TooManyArguments',
'error_message' => 'TooManyArguments - src/somefile.php:3 - Too many arguments for method fooFoo '
. '- expecting 1 but saw 2',
],
'tooManyArgumentsForConstructor' => [
'<?php

View File

@ -1368,7 +1368,7 @@ class TypeTest extends TestCase
class C extends A {}
function takesB(B $i): void {}',
'error_message' => 'TypeCoercion - src/somefile.php:11 - Argument 1 of takesb expects B,'
'error_message' => 'TypeCoercion - src/somefile.php:11 - Argument 1 of takesB expects B,'
. ' parent type A provided',
],
'intersectionTypeInterfaceCheckAfterInstanceof' => [
@ -1387,7 +1387,7 @@ class TypeTest extends TestCase
interface I {}
function takesI(I $i): void {}',
'error_message' => 'InvalidArgument - src/somefile.php:9 - Argument 1 of takesi expects I, A provided',
'error_message' => 'InvalidArgument - src/somefile.php:9 - Argument 1 of takesI expects I, A provided',
],
];
}