Skip to content

Sprintf with only one argument without formatting directives leads to false TooFewArguments #10021

@tscni

Description

@tscni

https://psalm.dev/r/6c9dd0f8b3

Presumably caused by

// it makes no sense to use sprintf when there is only 1 arg (the format)
// as it wouldn't have any placeholders
if (count($call_args) === 1 && $event->getFunctionId() === 'sprintf') {
IssueBuffer::maybeAdd(
new TooFewArguments(
'Too few arguments for ' . $event->getFunctionId() . ', expecting at least 2 arguments',
$event->getCodeLocation(),
$event->getFunctionId(),
),
$statements_source->getSuppressedIssues(),
);
return null;
}

It states

it makes no sense to use sprintf when there is only 1 arg (the format)
as it wouldn't have any placeholders

Which sure, is true, but that's a code style issue and not statically incorrect code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions