Skip to content

Commit 101467d

Browse files
committed
PrintfArrayParametersRule - ignore general arrays
1 parent 7c2d8b4 commit 101467d

File tree

3 files changed

+5
-9
lines changed

3 files changed

+5
-9
lines changed

src/Rules/Functions/PrintfArrayParametersRule.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use PHPStan\ShouldNotHappenException;
1212
use PHPStan\Type\Constant\ConstantIntegerType;
1313
use PHPStan\Type\IntegerRangeType;
14+
use PHPStan\Type\IntegerType;
1415
use PHPStan\Type\TypeCombinator;
1516
use function count;
1617
use function in_array;
@@ -87,13 +88,12 @@ public function processNode(Node $node, Scope $scope): array
8788
$formatArgsType = $scope->getType($args[1]->value);
8889

8990
$constantArrays = $formatArgsType->getConstantArrays();
91+
if ($constantArrays === []) {
92+
$formatArgsCounts[] = new IntegerType();
93+
}
9094
foreach ($constantArrays as $constantArray) {
9195
$formatArgsCounts[] = $constantArray->getArraySize();
9296
}
93-
94-
if ($constantArrays === []) {
95-
$formatArgsCounts[] = $formatArgsType->getArraySize();
96-
}
9797
}
9898

9999
if ($formatArgsCounts === []) {

tests/PHPStan/Rules/Functions/PrintfArrayParametersRuleTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ public function testFile(): void
6868
'Call to vprintf contains 2 placeholders, 1 value given.',
6969
34,
7070
],
71-
[
72-
'Call to vsprintf contains 1-2 placeholders, 0 or more values given.',
73-
53,
74-
],
7571
]);
7672
}
7773

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function doFoo($message, array $arr) {
5050
} else {
5151
$format = '%s%s';
5252
}
53-
vsprintf($format, $arr); // need at least non-empty-array
53+
vsprintf($format, $arr); // do not report on general array, annoying in practice
5454

5555
if (rand(0,1)) {
5656
$format = '%s';

0 commit comments

Comments
 (0)