From 3078763ec3fd6d398cf0bc657d202eda913d4eb6 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Wed, 2 Apr 2025 22:19:52 +0200 Subject: [PATCH] Misc/Fixup * floating changes * condense several switch() into match() constructs * fix ucFirst not making the rest of the word lowercase --- includes/types/item.class.php | 16 +++++----- includes/utilities.php | 13 ++++---- localization/lang.class.php | 60 ++++++++++++----------------------- pages/achievement.php | 15 +++------ pages/spell.php | 41 ++++++++---------------- 5 files changed, 53 insertions(+), 92 deletions(-) diff --git a/includes/types/item.class.php b/includes/types/item.class.php index a9d89238..9392685c 100644 --- a/includes/types/item.class.php +++ b/includes/types/item.class.php @@ -1488,15 +1488,15 @@ class ItemList extends BaseType { $mask = $this->curTpl['scalingStatValue']; - switch ($type) + $mask &= match ($type) { - case 'stats': $mask &= 0x04001F; break; - case 'armor': $mask &= 0xF001E0; break; - case 'dps' : $mask &= 0x007E00; break; - case 'spell': $mask &= 0x008000; break; - case 'fap' : $mask &= 0x010000; break; // unused - default: $mask &= 0x0; - } + 'stats' => 0x04001F, + 'armor' => 0xF001E0, + 'dps' => 0x007E00, + 'spell' => 0x008000, + 'fap' => 0x010000, // unused + default => 0x0 + }; $field = null; for ($i = 0; $i < count(Util::$ssdMaskFields); $i++) diff --git a/includes/utilities.php b/includes/utilities.php index 5edbe791..4b0e5d70 100644 --- a/includes/utilities.php +++ b/includes/utilities.php @@ -550,22 +550,21 @@ abstract class Util return Lang::item('ratingString', [$statId, $result, $level]); } - // default ucFirst doesn't convert UTF-8 chars - public static function ucFirst($str) + // default ucFirst doesn't convert UTF-8 chars (php 8.4 finally implemented this .. see ya in 2027) + public static function ucFirst(string $str) : string { - $len = mb_strlen($str) - 1; $first = mb_substr($str, 0, 1); - $rest = mb_substr($str, 1, $len); + $rest = mb_substr($str, 1); - return mb_strtoupper($first).$rest; + return mb_strtoupper($first).mb_strtolower($rest); } - public static function ucWords($str) + public static function ucWords(string $str) : string { return mb_convert_case($str, MB_CASE_TITLE); } - public static function lower($str) + public static function lower(string $str) : string { return mb_strtolower($str); } diff --git a/localization/lang.class.php b/localization/lang.class.php index 6a3d5ff0..90da9654 100644 --- a/localization/lang.class.php +++ b/localization/lang.class.php @@ -409,6 +409,7 @@ class Lang if ($short && $schoolMask == SPELL_ALL_SCHOOLS) return self::main('all'); + if ($short && $schoolMask == SPELL_MAGIC_SCHOOLS) return self::main('all').' ('.self::game('dt', 1).')'; @@ -429,27 +430,18 @@ class Lang { $classMask &= ChrClass::MASK_ALL; // clamp to available classes.. - if ($classMask == ChrClass::MASK_ALL) // available to all classes + if (!$classMask || $classMask == ChrClass::MASK_ALL)// available to all classes return ''; - $tmp = []; - - switch ($fmt) + [$base, $br] = match ($fmt) { - case self::FMT_HTML: - $base = '%2$s'; - $br = ''; - break; - case self::FMT_MARKUP: - $base = '[class=%1$d]'; - $br = '[br]'; - break; - case self::FMT_RAW: - default: - $base = '%2$s'; - $br = ''; - } + self::FMT_HTML => ['%2$s', ''], + self::FMT_MARKUP => ['[class=%1$d]', '[br]'], + self::FMT_RAW => ['%2$s', ''], + default => ['%2$s', ''] + }; + $tmp = []; foreach (ChrClass::fromMask($classMask) as $c) $tmp[$c] = (!fMod(count($tmp) + 1, 3) ? $br : null).sprintf($base, $c, self::game('cl', $c)); @@ -462,38 +454,26 @@ class Lang { $raceMask &= ChrRace::MASK_ALL; // clamp to available races.. - if ($raceMask == ChrRace::MASK_ALL) // available to all races (we don't display 'both factions') + if (!$raceMask || $raceMask == ChrRace::MASK_ALL) // available to all races (we don't display 'both factions') return ''; - if (!$raceMask) - return ''; - - $tmp = []; - - switch ($fmt) - { - case self::FMT_HTML: - $base = '%2$s'; - $br = ''; - break; - case self::FMT_MARKUP: - $base = '[race=%1$d]'; - $br = '[br]'; - break; - case self::FMT_RAW: - default: - $base = '%2$s'; - $br = ''; - } - if ($raceMask == ChrRace::MASK_HORDE) return self::game('ra', -2); if ($raceMask == ChrRace::MASK_ALLIANCE) return self::game('ra', -1); + [$base, $br] = match ($fmt) + { + self::FMT_HTML => ['%2$s', ''], + self::FMT_MARKUP => ['[race=%1$d]', '[br]'], + self::FMT_RAW => ['%2$s', ''], + default => ['%2$s', ''] + }; + + $tmp = []; foreach (ChrRace::fromMask($raceMask) as $r) - $tmp[$r] = (!fMod(count($tmp) + 1, 3) ? $br : null).sprintf($base, $r, self::game('ra', $r)); + $tmp[$r] = (!fMod(count($tmp) + 1, 3) ? $br : '').sprintf($base, $r, self::game('ra', $r)); $ids = array_keys($tmp); diff --git a/pages/achievement.php b/pages/achievement.php index ff11d36f..58010387 100644 --- a/pages/achievement.php +++ b/pages/achievement.php @@ -99,17 +99,12 @@ class AchievementPage extends GenericPage // todo (low) // faction - switch ($this->subject->getField('faction')) + $infobox[] = Lang::main('side').Lang::main('colon') . match ($this->subject->getField('faction')) { - case 1: - $infobox[] = Lang::main('side').Lang::main('colon').'[span class=icon-alliance]'.Lang::game('si', SIDE_ALLIANCE).'[/span]'; - break; - case 2: - $infobox[] = Lang::main('side').Lang::main('colon').'[span class=icon-horde]'.Lang::game('si', SIDE_HORDE).'[/span]'; - break; - default: // case 3 - $infobox[] = Lang::main('side').Lang::main('colon').Lang::game('si', SIDE_BOTH); - } + SIDE_ALLIANCE => '[span class=icon-alliance]'.Lang::game('si', SIDE_ALLIANCE).'[/span]', + SIDE_HORDE => '[span class=icon-horde]'.Lang::game('si', SIDE_HORDE).'[/span]', + default => Lang::game('si', SIDE_BOTH) // 0, 3 + }; // icon if ($_ = $this->subject->getField('iconId')) diff --git a/pages/spell.php b/pages/spell.php index 5a711be9..815ffb8a 100644 --- a/pages/spell.php +++ b/pages/spell.php @@ -1866,14 +1866,13 @@ class SpellPage extends GenericPage } break; case SPELL_EFFECT_SKINNING: - $_ = ''; - switch ($effMV) + $_ = match ($effMV) { - case 0: $_ = Lang::game('ct', 1).', '.Lang::game('ct', 2); break; // Skinning > Beast, Dragonkin - case 1: // Herb gathering > Elemental - case 2: $_ = Lang::game('ct', 4); break; // Mining > Elemental - case 3: $_ = Lang::game('ct', 9); break; // Dismantling > Mechanic - } + 0 => $_ = Lang::game('ct', 1).', '.Lang::game('ct', 2), // Skinning > Beast, Dragonkin + 1, 2 => $_ = Lang::game('ct', 4), // Gathering, Mining > Elemental + 3 => $_ = Lang::game('ct', 9), // Dismantling > Mechanic + default => '' + }; if ($_) $_nameMV = $this->fmtStaffTip($_, 'MiscValue: '.$effMV); break; @@ -2181,30 +2180,18 @@ class SpellPage extends GenericPage case SPELL_AURA_MOD_COMBAT_RESULT_CHANCE: $valueFmt = '%s%%'; case SPELL_AURA_IGNORE_COMBAT_RESULT: - $what = ''; - switch ($effMV) + $what = match ($effMV) { - case 2: // Dodged - $what = Lang::spell('combatRating', 2); - break; - case 3: // Blocked - $what = Lang::spell('combatRating', 4); - break; - case 4: // Parried - $what = Lang::spell('combatRating', 3); - break; - case 0; // Evaded - case 1: // Missed - case 5: // Glanced - case 6: // Crited'ed..ed - case 7: // Crushed - case 8: // Regular - default: - trigger_error('unused case #'.$effMV.' found for aura #'.$effAura); - } + 2 => Lang::spell('combatRating', 2), // Dodged + 3 => Lang::spell('combatRating', 4), // Blocked + 4 => Lang::spell('combatRating', 3), // Parried + default => '' // Evaded(0) Missed(1) Glanced(5) Crited'ed..ed(6) Crushed(7) Regular(8) + }; if ($what) $_nameMV = $this->fmtStaffTip($what, 'MiscValue: '.$effMV); + else + trigger_error('unused case #'.$effMV.' found for aura #'.$effAura); break; case SPELL_AURA_SCREEN_EFFECT: if ($ses = DB::Aowow()->selectRow('SELECT `name`, `ambienceDay` AS "0", IF(`ambienceNight` <> `ambienceDay`, `ambienceNight`, 0) AS "1", `musicDay` AS "2", IF(`musicNight` <> `musicDay`, `musicNight`, 0) AS "3" FROM ?_screeneffect_sounds WHERE `id` = ?d', $effMV))