Skip to content

Commit

Permalink
no error for printf with only 1 arg
Browse files Browse the repository at this point in the history
Fix #9987
  • Loading branch information
kkmuffme committed Jul 3, 2023
1 parent 768b813 commit 8d8adef
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
return null;
}

// it makes no sense to use sprintf/printf when there is only 1 arg (the format)
// 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) {
if (count($call_args) === 1 && $event->getFunctionId() === 'sprintf') {
IssueBuffer::maybeAdd(
new TooFewArguments(
'Too few arguments for ' . $event->getFunctionId() . ', expecting at least 2 arguments',
Expand Down
6 changes: 0 additions & 6 deletions tests/ReturnTypeProvider/SprintfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,6 @@ public function providerInvalidCodeParse(): iterable
',
'error_message' => 'InvalidArgument',
],
'printfOnlyFormat' => [
'code' => '<?php
printf("hello");
',
'error_message' => 'TooFewArguments',
],
'printfTooFewArguments' => [
'code' => '<?php
printf("%s hello %d", "a");
Expand Down

0 comments on commit 8d8adef

Please sign in to comment.