Skip to content
Permalink
Browse files

Fix #1811 - improve expected argument count

  • Loading branch information...
muglug committed Jun 19, 2019
1 parent d0e84f1 commit 7155ed4e06b17d9ab5bc5588e5a439c7ade88f44
Showing with 20 additions and 1 deletion.
  1. +15 −1 src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php
  2. +5 −0 tests/FunctionCallTest.php
@@ -1238,14 +1238,28 @@ protected static function checkFunctionLikeArgumentsMatch(
}
if (!$has_packed_var && count($args) < count($function_params)) {
if ($function_storage) {
$expected_param_count = $function_storage->required_param_count;
} else {
for ($i = 0, $j = count($function_params); $i < $j; ++$i) {
$param = $function_params[$i];
if ($param->is_optional || $param->is_variadic) {
break;
}
}
$expected_param_count = $i;
}
for ($i = count($args), $j = count($function_params); $i < $j; ++$i) {
$param = $function_params[$i];
if (!$param->is_optional && !$param->is_variadic) {
if (IssueBuffer::accepts(
new TooFewArguments(
'Too few arguments for method ' . $cased_method_id
. ' - expecting ' . count($function_params) . ' but saw ' . count($args),
. ' - expecting ' . $expected_param_count . ' but saw ' . count($args),
$code_location,
$method_id ?: ''
),
@@ -2269,6 +2269,11 @@ function bar($s) : void {
}',
'error_message' => 'InvalidScalarArgument'
],
'tooFewArgsAccurateCount' => [
'<?php
preg_match(\'/adsf/\');',
'error_message' => 'TooFewArguments - src' . DIRECTORY_SEPARATOR . 'somefile.php:2:21 - Too few arguments for method preg_match - expecting 2 but saw 1'
]
];
}
}

0 comments on commit 7155ed4

Please sign in to comment.
You can’t perform that action at this time.