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