| Conditions | 1 |
| Paths | 1 |
| Total Lines | 202 |
| Code Lines | 190 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 109 | private static function format_code_lang( $code = '' ) { |
||
| 110 | $code = strtolower( substr( $code, 0, 2 ) ); |
||
| 111 | $lang_codes = array( |
||
| 112 | 'aa' => 'Afar', |
||
| 113 | 'ab' => 'Abkhazian', |
||
| 114 | 'af' => 'Afrikaans', |
||
| 115 | 'ak' => 'Akan', |
||
| 116 | 'sq' => 'Albanian', |
||
| 117 | 'am' => 'Amharic', |
||
| 118 | 'ar' => 'Arabic', |
||
| 119 | 'an' => 'Aragonese', |
||
| 120 | 'hy' => 'Armenian', |
||
| 121 | 'as' => 'Assamese', |
||
| 122 | 'av' => 'Avaric', |
||
| 123 | 'ae' => 'Avestan', |
||
| 124 | 'ay' => 'Aymara', |
||
| 125 | 'az' => 'Azerbaijani', |
||
| 126 | 'ba' => 'Bashkir', |
||
| 127 | 'bm' => 'Bambara', |
||
| 128 | 'eu' => 'Basque', |
||
| 129 | 'be' => 'Belarusian', |
||
| 130 | 'bn' => 'Bengali', |
||
| 131 | 'bh' => 'Bihari', |
||
| 132 | 'bi' => 'Bislama', |
||
| 133 | 'bs' => 'Bosnian', |
||
| 134 | 'br' => 'Breton', |
||
| 135 | 'bg' => 'Bulgarian', |
||
| 136 | 'my' => 'Burmese', |
||
| 137 | 'ca' => 'Catalan; Valencian', |
||
| 138 | 'ch' => 'Chamorro', |
||
| 139 | 'ce' => 'Chechen', |
||
| 140 | 'zh' => 'Chinese', |
||
| 141 | 'cu' => 'Church Slavic; Old Slavonic; Church Slavonic; Old Bulgarian; Old Church Slavonic', |
||
| 142 | 'cv' => 'Chuvash', |
||
| 143 | 'kw' => 'Cornish', |
||
| 144 | 'co' => 'Corsican', |
||
| 145 | 'cr' => 'Cree', |
||
| 146 | 'cs' => 'Czech', |
||
| 147 | 'da' => 'Danish', |
||
| 148 | 'dv' => 'Divehi; Dhivehi; Maldivian', |
||
| 149 | 'nl' => 'Dutch; Flemish', |
||
| 150 | 'dz' => 'Dzongkha', |
||
| 151 | 'en' => 'English', |
||
| 152 | 'eo' => 'Esperanto', |
||
| 153 | 'et' => 'Estonian', |
||
| 154 | 'ee' => 'Ewe', |
||
| 155 | 'fo' => 'Faroese', |
||
| 156 | 'fj' => 'Fijjian', |
||
| 157 | 'fi' => 'Finnish', |
||
| 158 | 'fr' => 'French', |
||
| 159 | 'fy' => 'Western Frisian', |
||
| 160 | 'ff' => 'Fulah', |
||
| 161 | 'ka' => 'Georgian', |
||
| 162 | 'de' => 'German', |
||
| 163 | 'gd' => 'Gaelic; Scottish Gaelic', |
||
| 164 | 'ga' => 'Irish', |
||
| 165 | 'gl' => 'Galician', |
||
| 166 | 'gv' => 'Manx', |
||
| 167 | 'el' => 'Greek, Modern', |
||
| 168 | 'gn' => 'Guarani', |
||
| 169 | 'gu' => 'Gujarati', |
||
| 170 | 'ht' => 'Haitian; Haitian Creole', |
||
| 171 | 'ha' => 'Hausa', |
||
| 172 | 'he' => 'Hebrew', |
||
| 173 | 'hz' => 'Herero', |
||
| 174 | 'hi' => 'Hindi', |
||
| 175 | 'ho' => 'Hiri Motu', |
||
| 176 | 'hu' => 'Hungarian', |
||
| 177 | 'ig' => 'Igbo', |
||
| 178 | 'is' => 'Icelandic', |
||
| 179 | 'io' => 'Ido', |
||
| 180 | 'ii' => 'Sichuan Yi', |
||
| 181 | 'iu' => 'Inuktitut', |
||
| 182 | 'ie' => 'Interlingue', |
||
| 183 | 'ia' => 'Interlingua (International Auxiliary Language Association)', |
||
| 184 | 'id' => 'Indonesian', |
||
| 185 | 'ik' => 'Inupiaq', |
||
| 186 | 'it' => 'Italian', |
||
| 187 | 'jv' => 'Javanese', |
||
| 188 | 'ja' => 'Japanese', |
||
| 189 | 'kl' => 'Kalaallisut; Greenlandic', |
||
| 190 | 'kn' => 'Kannada', |
||
| 191 | 'ks' => 'Kashmiri', |
||
| 192 | 'kr' => 'Kanuri', |
||
| 193 | 'kk' => 'Kazakh', |
||
| 194 | 'km' => 'Central Khmer', |
||
| 195 | 'ki' => 'Kikuyu; Gikuyu', |
||
| 196 | 'rw' => 'Kinyarwanda', |
||
| 197 | 'ky' => 'Kirghiz; Kyrgyz', |
||
| 198 | 'kv' => 'Komi', |
||
| 199 | 'kg' => 'Kongo', |
||
| 200 | 'ko' => 'Korean', |
||
| 201 | 'kj' => 'Kuanyama; Kwanyama', |
||
| 202 | 'ku' => 'Kurdish', |
||
| 203 | 'lo' => 'Lao', |
||
| 204 | 'la' => 'Latin', |
||
| 205 | 'lv' => 'Latvian', |
||
| 206 | 'li' => 'Limburgan; Limburger; Limburgish', |
||
| 207 | 'ln' => 'Lingala', |
||
| 208 | 'lt' => 'Lithuanian', |
||
| 209 | 'lb' => 'Luxembourgish; Letzeburgesch', |
||
| 210 | 'lu' => 'Luba-Katanga', |
||
| 211 | 'lg' => 'Ganda', |
||
| 212 | 'mk' => 'Macedonian', |
||
| 213 | 'mh' => 'Marshallese', |
||
| 214 | 'ml' => 'Malayalam', |
||
| 215 | 'mi' => 'Maori', |
||
| 216 | 'mr' => 'Marathi', |
||
| 217 | 'ms' => 'Malay', |
||
| 218 | 'mg' => 'Malagasy', |
||
| 219 | 'mt' => 'Maltese', |
||
| 220 | 'mo' => 'Moldavian', |
||
| 221 | 'mn' => 'Mongolian', |
||
| 222 | 'na' => 'Nauru', |
||
| 223 | 'nv' => 'Navajo; Navaho', |
||
| 224 | 'nr' => 'Ndebele, South; South Ndebele', |
||
| 225 | 'nd' => 'Ndebele, North; North Ndebele', |
||
| 226 | 'ng' => 'Ndonga', |
||
| 227 | 'ne' => 'Nepali', |
||
| 228 | 'nn' => 'Norwegian Nynorsk; Nynorsk, Norwegian', |
||
| 229 | 'nb' => 'Bokmål, Norwegian, Norwegian Bokmål', |
||
| 230 | 'no' => 'Norwegian', |
||
| 231 | 'ny' => 'Chichewa; Chewa; Nyanja', |
||
| 232 | 'oc' => 'Occitan, Provençal', |
||
| 233 | 'oj' => 'Ojibwa', |
||
| 234 | 'or' => 'Oriya', |
||
| 235 | 'om' => 'Oromo', |
||
| 236 | 'os' => 'Ossetian; Ossetic', |
||
| 237 | 'pa' => 'Panjabi; Punjabi', |
||
| 238 | 'fa' => 'Persian', |
||
| 239 | 'pi' => 'Pali', |
||
| 240 | 'pl' => 'Polish', |
||
| 241 | 'pt' => 'Portuguese', |
||
| 242 | 'ps' => 'Pushto', |
||
| 243 | 'qu' => 'Quechua', |
||
| 244 | 'rm' => 'Romansh', |
||
| 245 | 'ro' => 'Romanian', |
||
| 246 | 'rn' => 'Rundi', |
||
| 247 | 'ru' => 'Russian', |
||
| 248 | 'sg' => 'Sango', |
||
| 249 | 'sa' => 'Sanskrit', |
||
| 250 | 'sr' => 'Serbian', |
||
| 251 | 'hr' => 'Croatian', |
||
| 252 | 'si' => 'Sinhala; Sinhalese', |
||
| 253 | 'sk' => 'Slovak', |
||
| 254 | 'sl' => 'Slovenian', |
||
| 255 | 'se' => 'Northern Sami', |
||
| 256 | 'sm' => 'Samoan', |
||
| 257 | 'sn' => 'Shona', |
||
| 258 | 'sd' => 'Sindhi', |
||
| 259 | 'so' => 'Somali', |
||
| 260 | 'st' => 'Sotho, Southern', |
||
| 261 | 'es' => 'Spanish; Castilian', |
||
| 262 | 'sc' => 'Sardinian', |
||
| 263 | 'ss' => 'Swati', |
||
| 264 | 'su' => 'Sundanese', |
||
| 265 | 'sw' => 'Swahili', |
||
| 266 | 'sv' => 'Swedish', |
||
| 267 | 'ty' => 'Tahitian', |
||
| 268 | 'ta' => 'Tamil', |
||
| 269 | 'tt' => 'Tatar', |
||
| 270 | 'te' => 'Telugu', |
||
| 271 | 'tg' => 'Tajik', |
||
| 272 | 'tl' => 'Tagalog', |
||
| 273 | 'th' => 'Thai', |
||
| 274 | 'bo' => 'Tibetan', |
||
| 275 | 'ti' => 'Tigrinya', |
||
| 276 | 'to' => 'Tonga (Tonga Islands)', |
||
| 277 | 'tn' => 'Tswana', |
||
| 278 | 'ts' => 'Tsonga', |
||
| 279 | 'tk' => 'Turkmen', |
||
| 280 | 'tr' => 'Turkish', |
||
| 281 | 'tw' => 'Twi', |
||
| 282 | 'ug' => 'Uighur; Uyghur', |
||
| 283 | 'uk' => 'Ukrainian', |
||
| 284 | 'ur' => 'Urdu', |
||
| 285 | 'uz' => 'Uzbek', |
||
| 286 | 've' => 'Venda', |
||
| 287 | 'vi' => 'Vietnamese', |
||
| 288 | 'vo' => 'Volapük', |
||
| 289 | 'cy' => 'Welsh', |
||
| 290 | 'wa' => 'Walloon', |
||
| 291 | 'wo' => 'Wolof', |
||
| 292 | 'xh' => 'Xhosa', |
||
| 293 | 'yi' => 'Yiddish', |
||
| 294 | 'yo' => 'Yoruba', |
||
| 295 | 'za' => 'Zhuang; Chuang', |
||
| 296 | 'zu' => 'Zulu' |
||
| 297 | ); |
||
| 298 | |||
| 299 | /** |
||
| 300 | * Filters the language codes. |
||
| 301 | * |
||
| 302 | * @since MU |
||
| 303 | * |
||
| 304 | * @param array $lang_codes Key/value pair of language codes where key is the short version. |
||
| 305 | * @param string $code A two-letter designation of the language. |
||
| 306 | */ |
||
| 307 | $lang_codes = apply_filters( 'lang_codes', $lang_codes, $code ); |
||
| 308 | |||
| 309 | return strtr( $code, $lang_codes ); |
||
| 310 | } |
||
| 311 | |||
| 313 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.