Skip to content

Commit

Permalink
code style + update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmuffme committed Aug 4, 2023
1 parent 0a58a68 commit 5483bf4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
Expand Up @@ -26,6 +26,7 @@
use function is_string;
use function preg_match;
use function sprintf;
use function strlen;

/**
* @internal
Expand Down Expand Up @@ -77,7 +78,7 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
new RedundantFunctionCall(
'Using the splat operator is redundant, as v' . $event->getFunctionId()
. ' without splat operator can be used instead of ' . $event->getFunctionId(),
$event->getCodeLocation()
$event->getCodeLocation(),
),
$statements_source->getSuppressedIssues(),
);
Expand All @@ -95,7 +96,7 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
new RedundantFunctionCall(
'Using ' . $event->getFunctionId()
. ' with a single argument is redundant, since there are no placeholder params to be substituted',
$event->getCodeLocation()
$event->getCodeLocation(),
),
$statements_source->getSuppressedIssues(),
);
Expand All @@ -122,8 +123,8 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
if ($type->getSingleStringLiteral()->value === '') {
IssueBuffer::maybeAdd(
new RedundantFunctionCall(
'Argument 1 of ' . $event->getFunctionId() . ' must not be an empty string',
$event->getCodeLocation()
'Calling ' . $event->getFunctionId() . ' with an empty first argument does nothing',
$event->getCodeLocation(),
),
$statements_source->getSuppressedIssues(),
);
Expand Down Expand Up @@ -180,7 +181,8 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
if ($result === $type->getSingleStringLiteral()->value) {
if (count($call_args) > 1) {
// we need to report this here too, since we return early without further validation
// otherwise people who have suspended RedundantFunctionCall errors will not get an error for this
// otherwise people who have suspended RedundantFunctionCall errors
// will not get an error for this
IssueBuffer::maybeAdd(
new TooManyArguments(
'Too many arguments for the number of placeholders in ' . $event->getFunctionId(),
Expand All @@ -196,7 +198,8 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
IssueBuffer::maybeAdd(
new RedundantFunctionCall(
'Using ' . $event->getFunctionId()
. ' with a single argument is redundant, since there are no placeholder params to be substituted',
. ' with a single argument is redundant,'
. ' since there are no placeholder params to be substituted',
$event->getCodeLocation()
),
$statements_source->getSuppressedIssues(),
Expand All @@ -206,7 +209,7 @@ public static function getFunctionReturnType(FunctionReturnTypeProviderEvent $ev
new RedundantFunctionCall(
'Argument 1 of ' . $event->getFunctionId()
. ' does not contain any placeholders',
$event->getCodeLocation()
$event->getCodeLocation(),
),
$statements_source->getSuppressedIssues(),
);
Expand Down
14 changes: 8 additions & 6 deletions tests/ReturnTypeProvider/SprintfTest.php
Expand Up @@ -142,7 +142,7 @@ public function providerValidCodeParse(): iterable
'$val===' => '\'\'',
],
'ignored_issues' => [
'InvalidArgument',
'RedundantFunctionCall',
],
];

Expand Down Expand Up @@ -221,7 +221,9 @@ public function providerValidCodeParse(): iterable
'assertions' => [
'$val===' => 'string',
],
'ignored_issues' => [],
'ignored_issues' => [
'RedundantFunctionCall',
],
'php_version' => '8.0',
];

Expand Down Expand Up @@ -297,9 +299,9 @@ public function providerInvalidCodeParse(): iterable
'code' => '<?php
printf(\'"%" hello\', "a");
',
'error_message' => [
'error_message' => 'TooManyArguments',
'ignored_issues' => [
'RedundantFunctionCall',
'TooManyArguments',
],
],
'sprintfEmptyFormat' => [
Expand All @@ -312,9 +314,9 @@ public function providerInvalidCodeParse(): iterable
'code' => '<?php
$x = sprintf("hello", "abc");
',
'error_message' => [
'error_message' => 'TooManyArguments',
'ignored_issues' => [
'RedundantFunctionCall',
'TooManyArguments',
],
],
'sprintfPaddedComplexEmptyStringFormat' => [
Expand Down

0 comments on commit 5483bf4

Please sign in to comment.