Skip to content

Commit 3d026d4

Browse files
committed
clean up
1 parent b7e16bc commit 3d026d4

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/Rules/Functions/PrintfHelper.php

+2-6
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ public function getPrintfPlaceholderAcceptingTypes(string $format): array
4040
{
4141
$placeholders = $this->parsePlaceholders(self::PRINTF_SPECIFIER_PATTERN, $format);
4242
$result = [];
43-
// int can go into float, string and mixed as well.
44-
// float can't go into int, but it can go to string/mixed.
45-
// string can go into mixed, but not into int/float.
46-
// mixed can only go into mixed.
43+
// Type on the left can go to the type on the right, but not vice versa.
4744
$typeSequenceMap = array_flip(['int', 'float', 'string', 'mixed']);
4845

4946
foreach ($placeholders as $position => $types) {
@@ -67,11 +64,10 @@ static function (Type $t) use ($types): bool {
6764
foreach ($types as $acceptingType) {
6865
$subresult = match ($acceptingType) {
6966
'strict-int' => (new IntegerType())->accepts($t, true)->yes(),
70-
// This allows float, constant non-numeric string, ...
7167
'int' => ! $t->toInteger() instanceof ErrorType,
7268
'float' => ! $t->toFloat() instanceof ErrorType,
7369
// The function signature already limits the parameters to stringable types, so there's
74-
// no point in checking it again here.
70+
// no point in checking string again here.
7571
'string', 'mixed' => true,
7672
};
7773

tests/PHPStan/Rules/Functions/data/printf-param-types.php

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ public function __toString(): string
4949
printf('%d', new \stdClass());
5050
printf('%s', []);
5151

52+
// Error, but already reported by PrintfParametersRule
53+
printf('%s');
54+
printf('%s', 1, 2);
55+
5256
// OK
5357
printf('%s', 'a');
5458
printf('%s', new FooStringable());

0 commit comments

Comments
 (0)