Skip to content

Commit b223e07

Browse files
committed
fix missing errors
1 parent 258ee7b commit b223e07

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

src/Rules/Functions/PrintfHelper.php

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -114,19 +114,16 @@ private function parsePlaceholders(string $specifiersPattern, string $format): a
114114
$placeholders = array_filter($matches, static fn (array $match): bool => strlen($match['before']) % 2 === 0);
115115

116116
$result = [];
117-
$positionToIdxMap = [];
118117
$positionalPlaceholders = [];
119-
$idx = $position = 0;
118+
$idx = 0;
120119

121120
foreach ($placeholders as $placeholder) {
122121
if (isset($placeholder['width']) && $placeholder['width'] !== '') {
123-
$result[$idx] = ['strict-int' => 1];
124-
$positionToIdxMap[$position++] = $idx++;
122+
$result[$idx++] = ['strict-int' => 1];
125123
}
126124

127125
if (isset($placeholder['precision']) && $placeholder['precision'] !== '') {
128-
$result[$idx] = ['strict-int' => 1];
129-
$positionToIdxMap[$position++] = $idx++;
126+
$result[$idx++] = ['strict-int' => 1];
130127
}
131128

132129
if (isset($placeholder['position']) && $placeholder['position'] !== '') {
@@ -135,8 +132,6 @@ private function parsePlaceholders(string $specifiersPattern, string $format): a
135132
continue;
136133
}
137134

138-
$position++;
139-
$positionToIdxMap[$position] = $idx;
140135
$result[$idx++][$this->getAcceptingTypeBySpecifier($placeholder['specifier'] ?? '')] = 1;
141136
}
142137

@@ -146,12 +141,7 @@ private function parsePlaceholders(string $specifiersPattern, string $format): a
146141
);
147142

148143
foreach ($positionalPlaceholders as $placeholder) {
149-
$idx = $positionToIdxMap[$placeholder['position']] ?? null;
150-
151-
if ($idx === null) {
152-
continue;
153-
}
154-
144+
$idx = $placeholder['position'] - 1;
155145
$result[$idx][$this->getAcceptingTypeBySpecifier($placeholder['specifier'] ?? '')] = 1;
156146
}
157147

tests/PHPStan/Rules/Functions/PrintfParameterTypeRuleTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,18 @@ public function test(): void
8484
'Placeholder #1 of function printf expects int, string given',
8585
26,
8686
],
87+
[
88+
'Placeholder #1 of function printf expects float, PrintfParamTypes\\FooStringable given',
89+
27,
90+
],
91+
[
92+
'Placeholder #1 of function printf expects float, PrintfParamTypes\\FooStringable given',
93+
28,
94+
],
95+
[
96+
'Placeholder #3 of function printf expects float, PrintfParamTypes\\FooStringable given',
97+
29,
98+
],
8799
]);
88100
}
89101

0 commit comments

Comments
 (0)