Skip to content

Commit 0e9c16d

Browse files
committed
fix missing errors
1 parent da2e9f7 commit 0e9c16d

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
@@ -116,19 +116,16 @@ private function parsePlaceholders(string $specifiersPattern, string $format): a
116116
$placeholders = array_filter($matches, static fn (array $match): bool => strlen($match['before']) % 2 === 0);
117117

118118
$result = [];
119-
$positionToIdxMap = [];
120119
$positionalPlaceholders = [];
121-
$idx = $position = 0;
120+
$idx = 0;
122121

123122
foreach ($placeholders as $placeholder) {
124123
if (isset($placeholder['width']) && $placeholder['width'] !== '') {
125-
$result[$idx] = ['strict-int' => 1];
126-
$positionToIdxMap[$position++] = $idx++;
124+
$result[$idx++] = ['strict-int' => 1];
127125
}
128126

129127
if (isset($placeholder['precision']) && $placeholder['precision'] !== '') {
130-
$result[$idx] = ['strict-int' => 1];
131-
$positionToIdxMap[$position++] = $idx++;
128+
$result[$idx++] = ['strict-int' => 1];
132129
}
133130

134131
if (isset($placeholder['position']) && $placeholder['position'] !== '') {
@@ -137,8 +134,6 @@ private function parsePlaceholders(string $specifiersPattern, string $format): a
137134
continue;
138135
}
139136

140-
$position++;
141-
$positionToIdxMap[$position] = $idx;
142137
$result[$idx++][$this->getAcceptingTypeBySpecifier($placeholder['specifier'] ?? '')] = 1;
143138
}
144139

@@ -148,12 +143,7 @@ private function parsePlaceholders(string $specifiersPattern, string $format): a
148143
);
149144

150145
foreach ($positionalPlaceholders as $placeholder) {
151-
$idx = $positionToIdxMap[$placeholder['position']] ?? null;
152-
153-
if ($idx === null) {
154-
continue;
155-
}
156-
146+
$idx = $placeholder['position'] - 1;
157147
$result[$idx][$this->getAcceptingTypeBySpecifier($placeholder['specifier'] ?? '')] = 1;
158148
}
159149

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)