Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 29 | class KuConverter extends LanguageConverter { |
||
| 30 | public $mArabicToLatin = [ |
||
| 31 | 'ب' => 'b', 'ج' => 'c', 'چ' => 'ç', 'د' => 'd', 'ف' => 'f', 'گ' => 'g', 'ھ' => 'h', |
||
| 32 | 'ہ' => 'h', 'ه' => 'h', 'ح' => 'h', 'ژ' => 'j', 'ك' => 'k', 'ک' => 'k', 'ل' => 'l', |
||
| 33 | 'م' => 'm', 'ن' => 'n', 'پ' => 'p', 'ق' => 'q', 'ر' => 'r', 'س' => 's', 'ش' => 'ş', |
||
| 34 | 'ت' => 't', 'ڤ' => 'v', 'خ' => 'x', 'غ' => 'x', 'ز' => 'z', |
||
| 35 | |||
| 36 | // ک و => ku -- ist richtig |
||
| 37 | // و ك=> ku -- ist auch richtig |
||
| 38 | |||
| 39 | /* Doppel- und Halbvokale */ |
||
| 40 | 'ڵ' => 'll', # ll |
||
| 41 | 'ڕ' => 'rr', # rr |
||
| 42 | 'ا' => 'a', |
||
| 43 | # 'ئێ' => 'ê', # initial e |
||
| 44 | 'ە' => 'e', |
||
| 45 | 'ه' => 'e', # with one non-joiner |
||
| 46 | 'ه' => 'e', # with two non-joiner |
||
| 47 | 'ة' => 'e', |
||
| 48 | 'ێ' => 'ê', |
||
| 49 | 'ي' => 'î', |
||
| 50 | 'ی' => 'î', # U+06CC db 8c ARABIC LETTER FARSI YEH |
||
| 51 | 'ى' => 'î', # U+0649 d9 89 ARABIC LETTER ALEF MAKSURA |
||
| 52 | 'ۆ' => 'o', |
||
| 53 | 'و' => 'w', |
||
| 54 | 'ئ' => '', # initial hemze should not be shown |
||
| 55 | '،' => ',', |
||
| 56 | 'ع' => '\'', # ayn |
||
| 57 | '؟' => '?', |
||
| 58 | |||
| 59 | # digits |
||
| 60 | '٠' => '0', # ٠ |
||
| 61 | '١' => '1', # ١ |
||
| 62 | '٢' => '2', # ٢ |
||
| 63 | '٣' => '3', # ٣ |
||
| 64 | '٤' => '4', # ٤ |
||
| 65 | '٥' => '5', # ٥ |
||
| 66 | '٦' => '6', # ٦ |
||
| 67 | '٧' => '7', # ٧ |
||
| 68 | '٨' => '8', # ٨ |
||
| 69 | '٩' => '9', # ٩ |
||
| 70 | ]; |
||
| 71 | |||
| 72 | public $mLatinToArabic = [ |
||
| 73 | 'b' => 'ب', 'c' => 'ج', 'ç' => 'چ', 'd' => 'د', 'f' => 'ف', 'g' => 'گ', |
||
| 74 | 'h' => 'ه', 'j' => 'ژ', 'k' => 'ک', 'l' => 'ل', |
||
| 75 | 'm' => 'م', 'n' => 'ن', 'p' => 'پ', 'q' => 'ق', 'r' => 'ر', 's' => 'س', 'ş' => 'ش', |
||
| 76 | 't' => 'ت', 'v' => 'ڤ', |
||
| 77 | 'x' => 'خ', 'y' => 'ی', 'z' => 'ز', |
||
| 78 | |||
| 79 | 'B' => 'ب', 'C' => 'ج', 'Ç' => 'چ', 'D' => 'د', 'F' => 'ف', 'G' => 'گ', 'H' => 'ھ', |
||
| 80 | 'H' => 'ہ', 'H' => 'ه', 'H' => 'ح', 'J' => 'ژ', 'K' => 'ك', 'K' => 'ک', 'L' => 'ل', |
||
| 81 | 'M' => 'م', 'N' => 'ن', 'P' => 'پ', 'Q' => 'ق', 'R' => 'ر', 'S' => 'س', 'Ş' => 'ش', |
||
| 82 | 'T' => 'ت', 'V' => 'ڤ', 'W' => 'و', 'X' => 'خ', |
||
| 83 | 'Y' => 'ی', 'Z' => 'ز', |
||
| 84 | |||
| 85 | /* Doppelkonsonanten */ |
||
| 86 | # 'll' => 'ڵ', # wenn es geht, doppel-l und l getrennt zu behandeln |
||
| 87 | # 'rr' => 'ڕ', # selbiges für doppel-r |
||
| 88 | |||
| 89 | /* Einzelne Großbuchstaben */ |
||
| 90 | // ' C' => 'ج', |
||
| 91 | |||
| 92 | /* Vowels */ |
||
| 93 | 'a' => 'ا', |
||
| 94 | 'e' => 'ە', |
||
| 95 | 'ê' => 'ێ', |
||
| 96 | 'i' => '', |
||
| 97 | 'î' => 'ی', |
||
| 98 | 'o' => 'ۆ', |
||
| 99 | 'u' => 'و', |
||
| 100 | 'û' => 'وو', |
||
| 101 | 'w' => 'و', |
||
| 102 | ',' => '،', |
||
| 103 | '?' => '؟', |
||
| 104 | |||
| 105 | # Try to replace the leading vowel |
||
| 106 | ' a' => 'ئا ', |
||
| 107 | ' e' => 'ئە ', |
||
| 108 | ' ê' => 'ئێ ', |
||
| 109 | ' î' => 'ئی ', |
||
| 110 | ' o' => 'ئۆ ', |
||
| 111 | ' u' => 'ئو ', |
||
| 112 | ' û' => 'ئوو ', |
||
| 113 | 'A' => 'ئا', |
||
| 114 | 'E' => 'ئە', |
||
| 115 | 'Ê' => 'ئێ', |
||
| 116 | 'Î' => 'ئی', |
||
| 117 | 'O' => 'ئۆ', |
||
| 118 | 'U' => 'ئو', |
||
| 119 | 'Û' => 'ئوو', |
||
| 120 | ' A' => 'ئا ', |
||
| 121 | ' E' => 'ئە ', |
||
| 122 | ' Ê' => 'ئێ ', |
||
| 123 | ' Î' => 'ئی ', |
||
| 124 | ' O' => 'ئۆ ', |
||
| 125 | ' U' => 'ئو ', |
||
| 126 | ' Û' => 'ئوو ', |
||
| 127 | # eyn erstmal deaktivieren, einfache Anführungsstriche sind einfach zu |
||
| 128 | # häufig, um sie als eyn zu interpretieren. |
||
| 129 | # '\'' => 'ع', |
||
| 130 | |||
| 131 | /* # deactivated for now, breaks links i.e. in header of Special:Recentchanges :-( |
||
| 132 | # digits |
||
| 133 | '0' => '٠', # ٠ |
||
| 134 | '1' => '١', # ١ |
||
| 135 | '2' => '٢', # ٢ |
||
| 136 | '3' => '٣', # ٣ |
||
| 137 | '4' => '٤', # ٤ |
||
| 138 | '5' => '٥', # ٥ |
||
| 139 | '6' => '٦', # ٦ |
||
| 140 | '7' => '٧', # ٧ |
||
| 141 | '8' => '٨', # ٨ |
||
| 142 | '9' => '٩', # ٩ |
||
| 143 | */ |
||
| 144 | ]; |
||
| 145 | |||
| 146 | function loadDefaultTables() { |
||
| 153 | |||
| 154 | /** |
||
| 155 | * A function wrapper: |
||
| 156 | * - if there is no selected variant, leave the link |
||
| 157 | * names as they were |
||
| 158 | * - do not try to find variants for usernames |
||
| 159 | * |
||
| 160 | * @param string &$link |
||
| 161 | * @param Title &$nt |
||
| 162 | * @param bool $ignoreOtherCond |
||
| 163 | */ |
||
| 164 | View Code Duplication | function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) { |
|
| 179 | |||
| 180 | /** |
||
| 181 | * It translates text into variant, specials: |
||
| 182 | * - ommiting roman numbers |
||
| 183 | * |
||
| 184 | * @param string $text |
||
| 185 | * @param bool $toVariant |
||
| 186 | * |
||
| 187 | * @throws MWException |
||
| 188 | * @return string |
||
| 189 | */ |
||
| 190 | function translate( $text, $toVariant ) { |
||
| 223 | } |
||
| 224 | |||
| 245 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.