Skip to content

Commit 023fa08

Browse files
Kolyunyaondrejmirtes
authored andcommitted
Fix printf parameters rule
1 parent dc63ae2 commit 023fa08

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

src/Rules/Functions/PrintfParametersRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function processNode(Node $node, Scope $scope): array
8282
private function getPlaceholdersCount(string $functionName, string $format): int
8383
{
8484
$specifiers = in_array($functionName, ['sprintf', 'printf'], true) ? '[bcdeEfFgGosuxX]' : '(?:[cdDeEfinosuxX]|\[\^[^\]]+\])';
85-
$pattern = '~(?<before>%*)%(?:(?<position>\d+)\$)?[-+]?(?:[ 0]|(?:\'[^%]))?-?\d*(?:\.\d+)?' . $specifiers . '~';
85+
$pattern = '~(?<before>%*)%(?:(?<position>\d+)\$)?[-+]?(?:[ 0]|(?:\'[^%]))?-?\d*(?:\.\d*)?' . $specifiers . '~';
8686

8787
if (!preg_match_all($pattern, $format, $matches, PREG_SET_ORDER)) {
8888
return 0;

tests/PHPStan/Rules/Functions/data/printf.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,7 @@
3333
sscanf($str, "%20[^\n]\n%d", $string, $number); // ok
3434
sscanf($str, "%20[^\n]\r\n%d", $string, $number); // ok
3535
sscanf($str, "%20[^abcde]a%d", $string, $number); // ok
36+
printf("%.E", 3.14159); // ok
37+
sprintf("%.E", 3.14159); // ok
38+
sscanf($str, '%.E', $number); // ok
39+
fscanf($str, '%.E', $number); // ok

0 commit comments

Comments
 (0)