Skip to content

Commit

Permalink
fix shepherd reported errors
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmuffme committed Mar 12, 2024
1 parent 1a715f9 commit 03bde5e
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/TemplateChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function analyze(?Context $file_context = null, ?Context $global_context
throw new InvalidArgumentException('Could not interpret doc comment correctly');
}

/** @psalm-suppress ArgumentTypeCoercion */
/** @psalm-suppress ArgumentTypeCoercion, TooFewArguments */
$method_id = new MethodIdentifier(...explode('::', $matches[1]));

$this_params = $this->checkMethod($method_id, $first_stmt, $codebase);
Expand Down
2 changes: 1 addition & 1 deletion examples/plugins/FunctionCasingChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static function afterMethodCallAnalysis(AfterMethodCallAnalysisEvent $eve
}

try {
/** @psalm-suppress ArgumentTypeCoercion */
/** @psalm-suppress ArgumentTypeCoercion, TooFewArguments */
$method_id = new MethodIdentifier(...explode('::', $declaring_method_id));
$function_storage = $codebase->methods->getStorage($method_id);

Expand Down
12 changes: 6 additions & 6 deletions src/Psalm/Codebase.php
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ public function getFunctionStorageForSymbol(string $file_path, string $symbol):
{
if (strpos($symbol, '::')) {
$symbol = substr($symbol, 0, -2);
/** @psalm-suppress ArgumentTypeCoercion */
/** @psalm-suppress ArgumentTypeCoercion, TooFewArguments */
$method_id = new MethodIdentifier(...explode('::', $symbol));

$declaring_method_id = $this->methods->getDeclaringMethodId($method_id);
Expand Down Expand Up @@ -1007,7 +1007,7 @@ public function getMarkupContentForSymbolByReference(
if (strpos($reference->symbol, '()')) {
$symbol = substr($reference->symbol, 0, -2);

/** @psalm-suppress ArgumentTypeCoercion */
/** @psalm-suppress ArgumentTypeCoercion, TooFewArguments */
$method_id = new MethodIdentifier(...explode('::', $symbol));

$declaring_method_id = $this->methods->getDeclaringMethodId(
Expand Down Expand Up @@ -1216,7 +1216,7 @@ public function getSymbolInformation(string $file_path, string $symbol): ?array
if (strpos($symbol, '()')) {
$symbol = substr($symbol, 0, -2);

/** @psalm-suppress ArgumentTypeCoercion */
/** @psalm-suppress ArgumentTypeCoercion, TooFewArguments */
$method_id = new MethodIdentifier(...explode('::', $symbol));

$declaring_method_id = $this->methods->getDeclaringMethodId($method_id);
Expand Down Expand Up @@ -1359,7 +1359,7 @@ public function getSymbolLocation(string $file_path, string $symbol): ?CodeLocat
if (strpos($symbol, '()')) {
$symbol = substr($symbol, 0, -2);

/** @psalm-suppress ArgumentTypeCoercion */
/** @psalm-suppress ArgumentTypeCoercion, TooFewArguments */
$method_id = new MethodIdentifier(...explode('::', $symbol));

$declaring_method_id = $this->methods->getDeclaringMethodId($method_id);
Expand Down Expand Up @@ -1445,7 +1445,7 @@ public function getSymbolLocationByReference(Reference $reference): ?CodeLocatio
if (strpos($reference->symbol, '()')) {
$symbol = substr($reference->symbol, 0, -2);

/** @psalm-suppress ArgumentTypeCoercion */
/** @psalm-suppress ArgumentTypeCoercion, TooFewArguments */
$method_id = new MethodIdentifier(
...explode('::', $symbol),
);
Expand Down Expand Up @@ -1656,7 +1656,7 @@ public function getSignatureInformation(
$signature_label = '';
$signature_documentation = null;
if (strpos($function_symbol, '::') !== false) {
/** @psalm-suppress ArgumentTypeCoercion */
/** @psalm-suppress ArgumentTypeCoercion, TooFewArguments */
$method_id = new MethodIdentifier(...explode('::', $function_symbol));

$declaring_method_id = $this->methods->getDeclaringMethodId($method_id);
Expand Down
1 change: 1 addition & 0 deletions src/Psalm/Config/Creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public static function getLevel(array $issues, int $counted_types): int
return array_keys($issues_at_level)[0] + 1;
}

/** @psalm-suppress TooFewArguments */
return max(...array_keys($issues_at_level)) + 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,9 @@ public static function checkArgumentsMatch(

$args_provided_min += $array_type->count ? ($array_type->count - 1) : 0;
} else {
if (isset($array_type->type_params[1]) && $array_type->type_params[1]->isNever()) {
if (isset($array_type->type_params[1])
&& $array_type->type_params[1] instanceof Union
&& $array_type->type_params[1]->isNever()) {
$args_provided_max--;
} else {
$args_provided_max = $function_param_count + 10_00_00_00_00;
Expand Down Expand Up @@ -981,11 +983,12 @@ public static function checkArgumentsMatch(
if ($has_unpacked_non_keyed_array && $args_provided_min < $required_args_count && $has_packed_var) {
IssueBuffer::maybeAdd(
new TooFewArguments(
'Possibly too few arguments for ' . ($cased_method_id ?: $method_id)
'Possibly too few arguments for '
. ($cased_method_id ?? (string) $method_id)
. ' - expecting ' . $required_args_count . ' but possibly only'
. ' ' . $args_provided_min . ' provided',
$code_location,
($cased_method_id ?: $method_id),
($cased_method_id ?? (string) $method_id),
),
$statements_analyzer->getSuppressedIssues(),
);
Expand All @@ -996,11 +999,12 @@ public static function checkArgumentsMatch(
// as it would often together otherwise
IssueBuffer::maybeAdd(
new TooManyArguments(
'Possibly too many arguments for ' . ($cased_method_id ?: $method_id)
'Possibly too many arguments for '
. ($cased_method_id ?? (string) $method_id)
. ' - expecting ' . $function_param_count . ' but saw'
. ' ' . ($args_provided_max > 5000 ? 'unlimited from unpacking' : $args_provided_max),
$code_location,
($cased_method_id ?: $method_id),
($cased_method_id ?? (string) $method_id),
),
$statements_analyzer->getSuppressedIssues(),
);
Expand Down Expand Up @@ -1307,6 +1311,7 @@ static function (
if ($by_ref_type && $function_param->is_variadic && $arg->unpack) {
// string unpacking available since 8.1
if ($codebase->analysis_php_version_id >= 8_01_00
&& $method_id
&& $codebase->getFunctionLikeStorage($statements_analyzer, $method_id)->allow_named_arg_calls
) {
$by_ref_type = new Union([
Expand Down Expand Up @@ -1775,7 +1780,8 @@ private static function checkArgCount(
) {
IssueBuffer::maybeAdd(
new TooManyArguments(
'Too many arguments for ' . ($cased_method_id ?: $method_id)
'Too many arguments for '
. ($cased_method_id ?? (string) $method_id)
. ' - expecting ' . count($function_params) . ' but saw ' . count($args),
$code_location,
(string)$method_id,
Expand Down
1 change: 1 addition & 0 deletions src/Psalm/Internal/Codebase/ClassLikes.php
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,7 @@ public function moveMethods(Methods $methods, ?Progress $progress = null): void
$source_parts = explode('::', $source);

try {
/** @psalm-suppress TooFewArguments */
$source_method_storage = $methods->getStorage(
new MethodIdentifier(...$source_parts),
);
Expand Down

0 comments on commit 03bde5e

Please sign in to comment.