|
14 | 14 | use function array_map;
|
15 | 15 | use function array_reduce;
|
16 | 16 | use function count;
|
| 17 | +use function in_array; |
17 | 18 | use function max;
|
18 | 19 | use function sort;
|
19 | 20 | use function sprintf;
|
@@ -64,14 +65,24 @@ public function getPrintfPlaceholderAcceptingTypes(string $format): array
|
64 | 65 | $typeName,
|
65 | 66 | static function (Type $t) use ($types): bool {
|
66 | 67 | foreach ($types as $acceptingType) {
|
67 |
| - $subresult = match ($acceptingType) { |
68 |
| - 'strict-int' => (new IntegerType())->accepts($t, true)->yes(), |
69 |
| - 'int' => ! $t->toInteger() instanceof ErrorType, |
70 |
| - 'float' => ! $t->toFloat() instanceof ErrorType, |
| 68 | + switch ($acceptingType) { |
| 69 | + case 'strict-int': |
| 70 | + $subresult = (new IntegerType())->accepts($t, true)->yes(); |
| 71 | + break; |
| 72 | + case 'int': |
| 73 | + $subresult = ! $t->toInteger() instanceof ErrorType; |
| 74 | + break; |
| 75 | + case 'float': |
| 76 | + $subresult = ! $t->toFloat() instanceof ErrorType; |
| 77 | + break; |
71 | 78 | // The function signature already limits the parameters to stringable types, so there's
|
72 | 79 | // no point in checking string again here.
|
73 |
| - 'string', 'mixed' => true, |
74 |
| - }; |
| 80 | + case 'string': |
| 81 | + case 'mixed': |
| 82 | + default: |
| 83 | + $subresult = true; |
| 84 | + break; |
| 85 | + } |
75 | 86 |
|
76 | 87 | if (!$subresult) {
|
77 | 88 | return false;
|
@@ -149,12 +160,19 @@ private function parsePlaceholders(string $specifiersPattern, string $format): a
|
149 | 160 | /** @phpstan-return 'string'|'int'|'float'|'mixed' */
|
150 | 161 | private function getAcceptingTypeBySpecifier(string $specifier): string
|
151 | 162 | {
|
152 |
| - return match ($specifier) { |
153 |
| - 's' => 'string', |
154 |
| - 'd', 'u', 'c', 'o', 'x', 'X', 'b' => 'int', |
155 |
| - 'e', 'E', 'f', 'F', 'g', 'G', 'h', 'H' => 'float', |
156 |
| - default => 'mixed', |
157 |
| - }; |
| 163 | + if ($specifier === 's') { |
| 164 | + return 'string'; |
| 165 | + } |
| 166 | + |
| 167 | + if (in_array($specifier, ['d', 'u', 'c', 'o', 'x', 'X', 'b'], true)) { |
| 168 | + return 'int'; |
| 169 | + } |
| 170 | + |
| 171 | + if (in_array($specifier, ['e', 'E', 'f', 'F', 'g', 'G', 'h', 'H'], true)) { |
| 172 | + return 'float'; |
| 173 | + } |
| 174 | + |
| 175 | + return 'mixed'; |
158 | 176 | }
|
159 | 177 |
|
160 | 178 | private function getPlaceholdersCount(string $specifiersPattern, string $format): int
|
|
0 commit comments