@@ -161,46 +161,12 @@ private function getAcceptingTypeBySpecifier(string $specifier): string
161
161
162
162
private function getPlaceholdersCount (string $ specifiersPattern , string $ format ): int
163
163
{
164
- $ addSpecifier = '' ;
165
- if ($ this ->phpVersion ->supportsHhPrintfSpecifier ()) {
166
- $ addSpecifier .= 'hH ' ;
167
- }
168
-
169
- $ specifiers = sprintf ($ specifiersPattern , $ addSpecifier );
170
-
171
- $ pattern = '~(?<before>%*)%(?:(?<position>\d+)\$)?[-+]?(?:[ 0]|(?: \'[^%]))?(?<width>\*)?-?\d*(?:\.(?:\d+|(?<precision>\*))?)? ' . $ specifiers . '~ ' ;
172
-
173
- $ matches = Strings::matchAll ($ format , $ pattern , PREG_SET_ORDER );
174
-
175
- if (count ($ matches ) === 0 ) {
176
- return 0 ;
177
- }
178
-
179
- $ placeholders = array_filter ($ matches , static fn (array $ match ): bool => strlen ($ match ['before ' ]) % 2 === 0 );
180
-
181
- if (count ($ placeholders ) === 0 ) {
182
- return 0 ;
183
- }
184
-
185
- $ maxPositionedNumber = 0 ;
186
- $ maxOrdinaryNumber = 0 ;
187
- foreach ($ placeholders as $ placeholder ) {
188
- if (isset ($ placeholder ['width ' ]) && $ placeholder ['width ' ] !== '' ) {
189
- $ maxOrdinaryNumber ++;
190
- }
191
-
192
- if (isset ($ placeholder ['precision ' ]) && $ placeholder ['precision ' ] !== '' ) {
193
- $ maxOrdinaryNumber ++;
194
- }
195
-
196
- if (isset ($ placeholder ['position ' ]) && $ placeholder ['position ' ] !== '' ) {
197
- $ maxPositionedNumber = max ((int ) $ placeholder ['position ' ], $ maxPositionedNumber );
198
- } else {
199
- $ maxOrdinaryNumber ++;
200
- }
201
- }
164
+ $ paramIndices = array_keys ($ this ->parsePlaceholders ($ specifiersPattern , $ format ));
202
165
203
- return max ($ maxPositionedNumber , $ maxOrdinaryNumber );
166
+ return $ paramIndices === []
167
+ ? 0
168
+ // The indices start from 0
169
+ : max ($ paramIndices ) + 1 ;
204
170
}
205
171
206
172
}
0 commit comments