Replaced some 'switch' with the 'match' expression (#1147)

* Replaced some 'switch' with the 'match' expression

* Update CHANGELOG.md
This commit is contained in:
Roman Kelesidis 2023-11-21 09:34:52 +07:00 committed by GitHub
commit 4cea325b6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 77 additions and 176 deletions

View file

@ -5,6 +5,7 @@
**Merged pull requests:** **Merged pull requests:**
- Replaced some 'switch' with the 'match' expression [\#1147](https://github.com/torrentpier/torrentpier/pull/1147) ([belomaxorka](https://github.com/belomaxorka))
- Vote button code improvements [\#1140](https://github.com/torrentpier/torrentpier/pull/1140), [\#1142](https://github.com/torrentpier/torrentpier/pull/1142), [\#1143](https://github.com/torrentpier/torrentpier/pull/1143), [\#1146](https://github.com/torrentpier/torrentpier/pull/1146) ([belomaxorka](https://github.com/belomaxorka)) - Vote button code improvements [\#1140](https://github.com/torrentpier/torrentpier/pull/1140), [\#1142](https://github.com/torrentpier/torrentpier/pull/1142), [\#1143](https://github.com/torrentpier/torrentpier/pull/1143), [\#1146](https://github.com/torrentpier/torrentpier/pull/1146) ([belomaxorka](https://github.com/belomaxorka))
- Vote button and v2 file list topic url display [\#1138](https://github.com/torrentpier/torrentpier/pull/1138) ([kovalensky](https://github.com/kovalensky)) - Vote button and v2 file list topic url display [\#1138](https://github.com/torrentpier/torrentpier/pull/1138) ([kovalensky](https://github.com/kovalensky))
- Removed topic watch useless code [\#1137](https://github.com/torrentpier/torrentpier/pull/1137) ([belomaxorka](https://github.com/belomaxorka)) - Removed topic watch useless code [\#1137](https://github.com/torrentpier/torrentpier/pull/1137) ([belomaxorka](https://github.com/belomaxorka))

View file

@ -46,23 +46,13 @@ if ($mc_type && $post['poster_id'] != $userdata['user_id']) {
\TorrentPier\Sessions::cache_rm_user_sessions($post['poster_id']); \TorrentPier\Sessions::cache_rm_user_sessions($post['poster_id']);
} }
switch ($mc_type) { $mc_class = match ($mc_type) {
case 1: // Комментарий 1 => 'success',
$mc_class = 'success'; 2 => 'info',
break; 3 => 'warning',
case 2: // Информация 4 => 'danger',
$mc_class = 'info'; default => '',
break; };
case 3: // Предупреждение
$mc_class = 'warning';
break;
case 4: // Нарушение
$mc_class = 'danger';
break;
default:
$mc_class = '';
break;
}
$this->response['mc_type'] = $mc_type; $this->response['mc_type'] = $mc_type;
$this->response['post_id'] = $post_id; $this->response['post_id'] = $post_id;

View file

@ -132,28 +132,15 @@ function create_thumbnail($source, $new_file, $mimetype)
$type = get_supported_image_types($type); $type = get_supported_image_types($type);
if ($type['gd']) { if ($type['gd']) {
switch ($type['format']) { $image = match ($type['format']) {
case IMG_GIF: IMG_GIF => imagecreatefromgif($source),
$image = imagecreatefromgif($source); IMG_JPG => imagecreatefromjpeg($source),
break; IMG_PNG => imagecreatefrompng($source),
case IMG_JPG: IMG_BMP => imagecreatefrombmp($source),
$image = imagecreatefromjpeg($source); IMG_WBMP => imagecreatefromwbmp($source),
break; IMG_WEBP => imagecreatefromwebp($source),
case IMG_PNG: default => throw new Exception('Unknown file format: ' . $type['format']),
$image = imagecreatefrompng($source); };
break;
case IMG_BMP:
$image = imagecreatefrombmp($source);
break;
case IMG_WBMP:
$image = imagecreatefromwbmp($source);
break;
case IMG_WEBP:
$image = imagecreatefromwebp($source);
break;
default:
throw new Exception('Unknown file format: ' . $type['format']);
}
if ($type['version'] == 1 || !$attach_config['use_gd2']) { if ($type['version'] == 1 || !$attach_config['use_gd2']) {
$new_image = imagecreate($new_width, $new_height); $new_image = imagecreate($new_width, $new_height);

View file

@ -384,30 +384,14 @@ function auth($type, $forum_id, $ug_data, array $f_access = [], $group_perm = UG
if (!isset($f_data[$auth_type])) { if (!isset($f_data[$auth_type])) {
continue; continue;
} }
switch ($f_data[$auth_type]) { $auth[$f_id][$auth_type] = match ($f_data[$auth_type]) {
case AUTH_ALL: AUTH_ALL => true,
$auth[$f_id][$auth_type] = true; AUTH_REG => !$is_guest,
break; AUTH_ACL => (auth_check('forum_perm', $auth_type, $u_access, $f_id, $is_admin) || $auth[$f_id]['auth_mod']),
AUTH_MOD => $auth[$f_id]['auth_mod'],
case AUTH_REG: AUTH_ADMIN => $is_admin,
$auth[$f_id][$auth_type] = !$is_guest; default => false,
break; };
case AUTH_ACL:
$auth[$f_id][$auth_type] = (auth_check('forum_perm', $auth_type, $u_access, $f_id, $is_admin) || $auth[$f_id]['auth_mod']);
break;
case AUTH_MOD:
$auth[$f_id][$auth_type] = $auth[$f_id]['auth_mod'];
break;
case AUTH_ADMIN:
$auth[$f_id][$auth_type] = $is_admin;
break;
default:
$auth[$f_id][$auth_type] = false;
}
if ($add_auth_type_desc) { if ($add_auth_type_desc) {
$auth[$f_id][$auth_type . '_type'] =& $lang['AUTH_TYPES'][$f_data[$auth_type]]; $auth[$f_id][$auth_type . '_type'] =& $lang['AUTH_TYPES'][$f_data[$auth_type]];
} }
@ -945,22 +929,13 @@ function get_db_stat($mode)
$row = DB()->sql_fetchrow($result); $row = DB()->sql_fetchrow($result);
switch ($mode) { return match ($mode) {
case 'usercount': 'usercount' => $row['total'],
return $row['total']; 'newestuser' => $row,
break; 'postcount' => $row['post_total'],
case 'newestuser': 'topiccount' => $row['topic_total'],
return $row; default => false,
break; };
case 'postcount':
return $row['post_total'];
break;
case 'topiccount':
return $row['topic_total'];
break;
}
return false;
} }
function clean_username($username) function clean_username($username)
@ -2001,19 +1976,11 @@ function gender_image($gender): string
return $user_gender; return $user_gender;
} }
switch ($gender) { return match ($gender) {
case MALE: MALE => '<img src="' . $images['icon_male'] . '" alt="' . $lang['GENDER_SELECT'][MALE] . '" title="' . $lang['GENDER_SELECT'][MALE] . '" border="0" />',
$user_gender = '<img src="' . $images['icon_male'] . '" alt="' . $lang['GENDER_SELECT'][MALE] . '" title="' . $lang['GENDER_SELECT'][MALE] . '" border="0" />'; FEMALE => '<img src="' . $images['icon_female'] . '" alt="' . $lang['GENDER_SELECT'][FEMALE] . '" title="' . $lang['GENDER_SELECT'][FEMALE] . '" border="0" />',
break; default => '<img src="' . $images['icon_nogender'] . '" alt="' . $lang['GENDER_SELECT'][NOGENDER] . '" title="' . $lang['GENDER_SELECT'][NOGENDER] . '" border="0" />',
case FEMALE: };
$user_gender = '<img src="' . $images['icon_female'] . '" alt="' . $lang['GENDER_SELECT'][FEMALE] . '" title="' . $lang['GENDER_SELECT'][FEMALE] . '" border="0" />';
break;
default:
$user_gender = '<img src="' . $images['icon_nogender'] . '" alt="' . $lang['GENDER_SELECT'][NOGENDER] . '" title="' . $lang['GENDER_SELECT'][NOGENDER] . '" border="0" />';
break;
}
return $user_gender;
} }
function is_gold($type): string function is_gold($type): string

View file

@ -205,23 +205,13 @@ if (!$is_auth[$is_auth_type]) {
bb_die(sprintf($lang['SORRY_' . strtoupper($is_auth_type)], $is_auth[$is_auth_type . '_type'])); bb_die(sprintf($lang['SORRY_' . strtoupper($is_auth_type)], $is_auth[$is_auth_type . '_type']));
} }
switch ($mode) { $redirect = match ($mode) {
case 'newtopic': 'newtopic' => "mode=newtopic&f=$forum_id",
$redirect = "mode=newtopic&f=$forum_id"; 'new_rel' => "mode=new_rel&f=$forum_id",
break; 'reply' => "mode=reply&t=$topic_id",
case 'new_rel': 'quote', 'editpost' => "mode=quote&p=$post_id",
$redirect = "mode=new_rel&f=$forum_id"; default => '',
break; };
case 'reply':
$redirect = "mode=reply&t=$topic_id";
break;
case 'quote':
case 'editpost':
$redirect = "mode=quote&p=$post_id";
break;
default:
$redirect = '';
}
redirect(LOGIN_URL . "?redirect=/" . POSTING_URL . "?$redirect"); redirect(LOGIN_URL . "?redirect=/" . POSTING_URL . "?$redirect");
} }

View file

@ -1335,20 +1335,12 @@ if ($mode == 'read') {
$template->assign_var('PM_BOX_SIZE_INFO'); $template->assign_var('PM_BOX_SIZE_INFO');
switch ($folder) { $l_box_size_status = match ($folder) {
case 'inbox': 'inbox' => sprintf($lang['INBOX_SIZE'], $box_limit_percent),
$l_box_size_status = sprintf($lang['INBOX_SIZE'], $box_limit_percent); 'sentbox' => sprintf($lang['SENTBOX_SIZE'], $box_limit_percent),
break; 'savebox' => sprintf($lang['SAVEBOX_SIZE'], $box_limit_percent),
case 'sentbox': default => '',
$l_box_size_status = sprintf($lang['SENTBOX_SIZE'], $box_limit_percent); };
break;
case 'savebox':
$l_box_size_status = sprintf($lang['SAVEBOX_SIZE'], $box_limit_percent);
break;
default:
$l_box_size_status = '';
break;
}
} }
// //

View file

@ -293,15 +293,11 @@ class Ajax
} }
foreach (debug_backtrace() as $trace) { foreach (debug_backtrace() as $trace) {
if (!empty($trace['file']) && $trace['file'] !== __FILE__) { if (!empty($trace['file']) && $trace['file'] !== __FILE__) {
switch ($mode) { return match ($mode) {
case 'file': 'file' => $trace['file'],
return $trace['file']; 'line' => $trace['line'],
case 'line': default => hide_bb_path($trace['file']) . '(' . $trace['line'] . ')',
return $trace['line']; };
case 'all':
default:
return hide_bb_path($trace['file']) . '(' . $trace['line'] . ')';
}
} }
} }
return 'src not found'; return 'src not found';

View file

@ -100,15 +100,11 @@ class Common
} }
foreach (debug_backtrace() as $trace) { foreach (debug_backtrace() as $trace) {
if (!empty($trace['file']) && $trace['file'] !== __FILE__) { if (!empty($trace['file']) && $trace['file'] !== __FILE__) {
switch ($mode) { return match ($mode) {
case 'file': 'file' => $trace['file'],
return $trace['file']; 'line' => $trace['line'],
case 'line': default => hide_bb_path($trace['file']) . '(' . $trace['line'] . ')',
return $trace['line']; };
case 'all':
default:
return hide_bb_path($trace['file']) . '(' . $trace['line'] . ')';
}
} }
} }
return 'src not found'; return 'src not found';

View file

@ -174,15 +174,11 @@ class Common
} }
foreach (debug_backtrace() as $trace) { foreach (debug_backtrace() as $trace) {
if (!empty($trace['file']) && $trace['file'] !== __FILE__) { if (!empty($trace['file']) && $trace['file'] !== __FILE__) {
switch ($mode) { return match ($mode) {
case 'file': 'file' => $trace['file'],
return $trace['file']; 'line' => $trace['line'],
case 'line': default => hide_bb_path($trace['file']) . '(' . $trace['line'] . ')',
return $trace['line']; };
case 'all':
default:
return hide_bb_path($trace['file']) . '(' . $trace['line'] . ')';
}
} }
} }
return 'src not found'; return 'src not found';

View file

@ -854,15 +854,11 @@ class SqlDb
} }
foreach (debug_backtrace() as $trace) { foreach (debug_backtrace() as $trace) {
if (!empty($trace['file']) && $trace['file'] !== __FILE__) { if (!empty($trace['file']) && $trace['file'] !== __FILE__) {
switch ($mode) { return match ($mode) {
case 'file': 'file' => $trace['file'],
return $trace['file']; 'line' => $trace['line'],
case 'line': default => hide_bb_path($trace['file']) . '(' . $trace['line'] . ')',
return $trace['line']; };
case 'all':
default:
return hide_bb_path($trace['file']) . '(' . $trace['line'] . ')';
}
} }
} }
return 'src not found'; return 'src not found';

View file

@ -666,23 +666,13 @@ for ($i = 0; $i < $total_posts; $i++) {
$pg_row_class = !($i % 2) ? 'row2' : 'row1'; $pg_row_class = !($i % 2) ? 'row2' : 'row1';
// Mod comment // Mod comment
switch ($mc_type) { $mc_class = match ($mc_type) {
case 1: // Комментарий 1 => 'success',
$mc_class = 'success'; 2 => 'info',
break; 3 => 'warning',
case 2: // Информация 4 => 'danger',
$mc_class = 'info'; default => '',
break; };
case 3: // Предупреждение
$mc_class = 'warning';
break;
case 4: // Нарушение
$mc_class = 'danger';
break;
default:
$mc_class = '';
break;
}
$mc_select_type = []; $mc_select_type = [];
foreach ($lang['MC_COMMENT'] as $key => $value) { foreach ($lang['MC_COMMENT'] as $key => $value) {
$mc_select_type[$key] = $value['type']; $mc_select_type[$key] = $value['type'];