Skip to content

Commit 9a4e490

Browse files
committed
replace match with switch
1 parent 3d026d4 commit 9a4e490

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

src/Rules/Functions/PrintfHelper.php

+30-12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use function array_map;
1414
use function array_reduce;
1515
use function count;
16+
use function in_array;
1617
use function max;
1718
use function sort;
1819
use function sprintf;
@@ -62,14 +63,24 @@ public function getPrintfPlaceholderAcceptingTypes(string $format): array
6263
$typeName,
6364
static function (Type $t) use ($types): bool {
6465
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;
6976
// The function signature already limits the parameters to stringable types, so there's
7077
// 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+
}
7384

7485
if (!$subresult) {
7586
return false;
@@ -147,12 +158,19 @@ private function parsePlaceholders(string $specifiersPattern, string $format): a
147158
/** @phpstan-return 'string'|'int'|'float'|'mixed' */
148159
private function getAcceptingTypeBySpecifier(string $specifier): string
149160
{
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';
156174
}
157175

158176
private function getPlaceholdersCount(string $specifiersPattern, string $format): int

0 commit comments

Comments
 (0)