Skip to content

Commit e854e79

Browse files
Merge pull request #18086 from kamil-tekiela/Replace-switch-with-match
Replace switch with match
2 parents 26b5860 + 69f8d9f commit e854e79

18 files changed

Lines changed: 371 additions & 701 deletions

libraries/classes/Charsets/Collation.php

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -252,22 +252,13 @@ private function buildName(string $result, ?string $variant, array $suffixes): s
252252

253253
private function getVariant(string $part): ?string
254254
{
255-
switch ($part) {
256-
case '0900':
257-
return 'UCA 9.0.0';
258-
259-
case '520':
260-
return 'UCA 5.2.0';
261-
262-
case 'mysql561':
263-
return 'MySQL 5.6.1';
264-
265-
case 'mysql500':
266-
return 'MySQL 5.0.0';
267-
268-
default:
269-
return null;
270-
}
255+
return match ($part) {
256+
'0900' => 'UCA 9.0.0',
257+
'520' => 'UCA 5.2.0',
258+
'mysql561' => 'MySQL 5.6.1',
259+
'mysql500' => 'MySQL 5.0.0',
260+
default => null,
261+
};
271262
}
272263

273264
/**

libraries/classes/Config/Settings.php

Lines changed: 35 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -2777,26 +2777,13 @@ private function setNavigationTreeDefaultTabTable(array $settings): string
27772777
return 'structure';
27782778
}
27792779

2780-
switch ($settings['NavigationTreeDefaultTabTable']) {
2781-
case 'sql':
2782-
case 'tbl_sql.php':
2783-
return 'sql';
2784-
2785-
case 'search':
2786-
case 'tbl_select.php':
2787-
return 'search';
2788-
2789-
case 'insert':
2790-
case 'tbl_change.php':
2791-
return 'insert';
2792-
2793-
case 'browse':
2794-
case 'sql.php':
2795-
return 'browse';
2796-
2797-
default:
2798-
return 'structure';
2799-
}
2780+
return match ($settings['NavigationTreeDefaultTabTable']) {
2781+
'sql', 'tbl_sql.php' => 'sql',
2782+
'search', 'tbl_select.php' => 'search',
2783+
'insert', 'tbl_change.php' => 'insert',
2784+
'browse', 'sql.php' => 'browse',
2785+
default => 'structure',
2786+
};
28002787
}
28012788

28022789
/**
@@ -2810,30 +2797,14 @@ private function setNavigationTreeDefaultTabTable2(array $settings): string
28102797
return '';
28112798
}
28122799

2813-
switch ($settings['NavigationTreeDefaultTabTable2']) {
2814-
case 'structure':
2815-
case 'tbl_structure.php':
2816-
return 'structure';
2817-
2818-
case 'sql':
2819-
case 'tbl_sql.php':
2820-
return 'sql';
2821-
2822-
case 'search':
2823-
case 'tbl_select.php':
2824-
return 'search';
2825-
2826-
case 'insert':
2827-
case 'tbl_change.php':
2828-
return 'insert';
2829-
2830-
case 'browse':
2831-
case 'sql.php':
2832-
return 'browse';
2833-
2834-
default:
2835-
return '';
2836-
}
2800+
return match ($settings['NavigationTreeDefaultTabTable2']) {
2801+
'structure', 'tbl_structure.php' => 'structure',
2802+
'sql', 'tbl_sql.php' => 'sql',
2803+
'search', 'tbl_select.php' => 'search',
2804+
'insert', 'tbl_change.php' => 'insert',
2805+
'browse', 'sql.php' => 'browse',
2806+
default => '',
2807+
};
28372808
}
28382809

28392810
/**
@@ -3449,26 +3420,13 @@ private function setDefaultTabServer(array $settings): string
34493420
return 'welcome';
34503421
}
34513422

3452-
switch ($settings['DefaultTabServer']) {
3453-
case 'databases':
3454-
case 'server_databases.php':
3455-
return 'databases';
3456-
3457-
case 'status':
3458-
case 'server_status.php':
3459-
return 'status';
3460-
3461-
case 'variables':
3462-
case 'server_variables.php':
3463-
return 'variables';
3464-
3465-
case 'privileges':
3466-
case 'server_privileges.php':
3467-
return 'privileges';
3468-
3469-
default:
3470-
return 'welcome';
3471-
}
3423+
return match ($settings['DefaultTabServer']) {
3424+
'databases', 'server_databases.php' => 'databases',
3425+
'status', 'server_status.php' => 'status',
3426+
'variables', 'server_variables.php' => 'variables',
3427+
'privileges', 'server_privileges.php' => 'privileges',
3428+
default => 'welcome',
3429+
};
34723430
}
34733431

34743432
/**
@@ -3482,22 +3440,12 @@ private function setDefaultTabDatabase(array $settings): string
34823440
return 'structure';
34833441
}
34843442

3485-
switch ($settings['DefaultTabDatabase']) {
3486-
case 'sql':
3487-
case 'db_sql.php':
3488-
return 'sql';
3489-
3490-
case 'search':
3491-
case 'db_search.php':
3492-
return 'search';
3493-
3494-
case 'operations':
3495-
case 'db_operations.php':
3496-
return 'operations';
3497-
3498-
default:
3499-
return 'structure';
3500-
}
3443+
return match ($settings['DefaultTabDatabase']) {
3444+
'sql', 'db_sql.php' => 'sql',
3445+
'search', 'db_search.php' => 'search',
3446+
'operations', 'db_operations.php' => 'operations',
3447+
default => 'structure',
3448+
};
35013449
}
35023450

35033451
/**
@@ -3511,26 +3459,13 @@ private function setDefaultTabTable(array $settings): string
35113459
return 'browse';
35123460
}
35133461

3514-
switch ($settings['DefaultTabTable']) {
3515-
case 'structure':
3516-
case 'tbl_structure.php':
3517-
return 'structure';
3518-
3519-
case 'sql':
3520-
case 'tbl_sql.php':
3521-
return 'sql';
3522-
3523-
case 'search':
3524-
case 'tbl_select.php':
3525-
return 'search';
3526-
3527-
case 'insert':
3528-
case 'tbl_change.php':
3529-
return 'insert';
3530-
3531-
default:
3532-
return 'browse';
3533-
}
3462+
return match ($settings['DefaultTabTable']) {
3463+
'structure', 'tbl_structure.php' => 'structure',
3464+
'sql', 'tbl_sql.php' => 'sql',
3465+
'search', 'tbl_select.php' => 'search',
3466+
'insert', 'tbl_change.php' => 'insert',
3467+
default => 'browse',
3468+
};
35343469
}
35353470

35363471
/**

libraries/classes/DatabaseInterface.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,16 +1043,11 @@ public function getVariable(
10431043
int $type = self::GETVAR_SESSION,
10441044
int $connectionType = Connection::TYPE_USER
10451045
) {
1046-
switch ($type) {
1047-
case self::GETVAR_SESSION:
1048-
$modifier = ' SESSION';
1049-
break;
1050-
case self::GETVAR_GLOBAL:
1051-
$modifier = ' GLOBAL';
1052-
break;
1053-
default:
1054-
$modifier = '';
1055-
}
1046+
$modifier = match ($type) {
1047+
self::GETVAR_SESSION => ' SESSION',
1048+
self::GETVAR_GLOBAL => ' GLOBAL',
1049+
default => '',
1050+
};
10561051

10571052
return $this->fetchValue('SHOW' . $modifier . ' VARIABLES LIKE \'' . $var . '\';', 1, $connectionType);
10581053
}

libraries/classes/Encoding.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -185,19 +185,16 @@ public static function convertString(
185185
self::initEngine();
186186
}
187187

188-
switch (self::$engine) {
189-
case self::ENGINE_RECODE:
190-
return recode_string($src_charset . '..' . $dest_charset, $what);
191-
192-
case self::ENGINE_ICONV:
193-
return iconv($src_charset, $dest_charset . ($GLOBALS['cfg']['IconvExtraParams'] ?? ''), $what);
194-
195-
case self::ENGINE_MB:
196-
return mb_convert_encoding($what, $dest_charset, $src_charset);
197-
198-
default:
199-
return $what;
200-
}
188+
return match (self::$engine) {
189+
self::ENGINE_RECODE => recode_string($src_charset . '..' . $dest_charset, $what),
190+
self::ENGINE_ICONV => iconv(
191+
$src_charset,
192+
$dest_charset . ($GLOBALS['cfg']['IconvExtraParams'] ?? ''),
193+
$what
194+
),
195+
self::ENGINE_MB => mb_convert_encoding($what, $dest_charset, $src_charset),
196+
default => $what,
197+
};
201198
}
202199

203200
/**

libraries/classes/Gis/GisFactory.php

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,15 @@ class GisFactory
2525
*/
2626
public static function factory($type)
2727
{
28-
switch (strtoupper($type)) {
29-
case 'MULTIPOLYGON':
30-
return GisMultiPolygon::singleton();
31-
32-
case 'POLYGON':
33-
return GisPolygon::singleton();
34-
35-
case 'MULTIPOINT':
36-
return GisMultiPoint::singleton();
37-
38-
case 'POINT':
39-
return GisPoint::singleton();
40-
41-
case 'MULTILINESTRING':
42-
return GisMultiLineString::singleton();
43-
44-
case 'LINESTRING':
45-
return GisLineString::singleton();
46-
47-
case 'GEOMETRYCOLLECTION':
48-
return GisGeometryCollection::singleton();
49-
50-
default:
51-
return false;
52-
}
28+
return match (strtoupper($type)) {
29+
'MULTIPOLYGON' => GisMultiPolygon::singleton(),
30+
'POLYGON' => GisPolygon::singleton(),
31+
'MULTIPOINT' => GisMultiPoint::singleton(),
32+
'POINT' => GisPoint::singleton(),
33+
'MULTILINESTRING' => GisMultiLineString::singleton(),
34+
'LINESTRING' => GisLineString::singleton(),
35+
'GEOMETRYCOLLECTION' => GisGeometryCollection::singleton(),
36+
default => false,
37+
};
5338
}
5439
}

libraries/classes/InsertEdit.php

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -364,15 +364,11 @@ public function showTypeOrFunction($which, array $urlParams, $isShow): string
364364
*/
365365
private function showTypeOrFunctionLabel($which): string
366366
{
367-
switch ($which) {
368-
case 'function':
369-
return __('Function');
370-
371-
case 'type':
372-
return __('Type');
373-
}
374-
375-
return '';
367+
return match ($which) {
368+
'function' => __('Function'),
369+
'type' => __('Type'),
370+
default => '',
371+
};
376372
}
377373

378374
/**
@@ -476,35 +472,28 @@ public function isColumn(array $column, array $types): bool
476472
*/
477473
private function getEnumSetAndTimestampColumns(array $column, $timestampSeen)
478474
{
479-
switch ($column['True_Type']) {
480-
case 'set':
481-
return [
482-
'set',
483-
'',
484-
false,
485-
];
486-
487-
case 'enum':
488-
return [
489-
'enum',
490-
'',
491-
false,
492-
];
493-
494-
case 'timestamp':
495-
return [
496-
$column['Type'],
497-
' text-nowrap',
498-
! $timestampSeen, // can only occur once per table
499-
];
500-
501-
default:
502-
return [
503-
$column['Type'],
504-
' text-nowrap',
505-
false,
506-
];
507-
}
475+
return match ($column['True_Type']) {
476+
'set' => [
477+
'set',
478+
'',
479+
false,
480+
],
481+
'enum' => [
482+
'enum',
483+
'',
484+
false,
485+
],
486+
'timestamp' => [
487+
$column['Type'],
488+
' text-nowrap',
489+
! $timestampSeen, // can only occur once per table
490+
],
491+
default => [
492+
$column['Type'],
493+
' text-nowrap',
494+
false,
495+
],
496+
};
508497
}
509498

510499
/**

libraries/classes/Navigation/Nodes/NodeColumn.php

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,13 @@ public function __construct($item, $type = Node::OBJECT, $isGroup = false)
5151
*
5252
* @return string Icon name for required key.
5353
*/
54-
private function getColumnIcon($key)
54+
private function getColumnIcon($key): string
5555
{
56-
switch ($key) {
57-
case 'PRI':
58-
$retval = 'b_primary';
59-
break;
60-
case 'UNI':
61-
$retval = 'bd_primary';
62-
break;
63-
default:
64-
$retval = 'pause';
65-
break;
66-
}
67-
68-
return $retval;
56+
return match ($key) {
57+
'PRI' => 'b_primary',
58+
'UNI' => 'bd_primary',
59+
default => 'pause',
60+
};
6961
}
7062

7163
/**

0 commit comments

Comments
 (0)