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