| Conditions | 6 |
| Paths | 8 |
| Total Lines | 90 |
| Code Lines | 77 |
| 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 |
||
| 24 | public function __construct($code = null) |
||
| 25 | { |
||
| 26 | $this->db = Registry::get('Db'); |
||
| 27 | |||
| 28 | $Qlanguages = $this->db->prepare('select languages_id, name, code, image, directory from :table_languages order by sort_order'); |
||
| 29 | $Qlanguages->setCache('languages-system'); |
||
| 30 | $Qlanguages->execute(); |
||
| 31 | |||
| 32 | while ($Qlanguages->fetch()) { |
||
| 33 | $this->languages[$Qlanguages->value('code')] = [ |
||
| 34 | 'id' => $Qlanguages->valueInt('languages_id'), |
||
| 35 | 'code' => $Qlanguages->value('code'), |
||
| 36 | 'name' => $Qlanguages->value('name'), |
||
| 37 | 'image' => $Qlanguages->value('image'), |
||
| 38 | 'directory' => $Qlanguages->value('directory') |
||
| 39 | ]; |
||
| 40 | } |
||
| 41 | |||
| 42 | $this->detectors = [ |
||
| 43 | 'af' => 'af|afrikaans', |
||
| 44 | 'ar' => 'ar([-_][[:alpha:]]{2})?|arabic', |
||
| 45 | 'be' => 'be|belarusian', |
||
| 46 | 'bg' => 'bg|bulgarian', |
||
| 47 | 'br' => 'pt[-_]br|brazilian portuguese', |
||
| 48 | 'ca' => 'ca|catalan', |
||
| 49 | 'cs' => 'cs|czech', |
||
| 50 | 'da' => 'da|danish', |
||
| 51 | 'de' => 'de([-_][[:alpha:]]{2})?|german', |
||
| 52 | 'el' => 'el|greek', |
||
| 53 | 'en' => 'en([-_][[:alpha:]]{2})?|english', |
||
| 54 | 'es' => 'es([-_][[:alpha:]]{2})?|spanish', |
||
| 55 | 'et' => 'et|estonian', |
||
| 56 | 'eu' => 'eu|basque', |
||
| 57 | 'fa' => 'fa|farsi', |
||
| 58 | 'fi' => 'fi|finnish', |
||
| 59 | 'fo' => 'fo|faeroese', |
||
| 60 | 'fr' => 'fr([-_][[:alpha:]]{2})?|french', |
||
| 61 | 'ga' => 'ga|irish', |
||
| 62 | 'gl' => 'gl|galician', |
||
| 63 | 'he' => 'he|hebrew', |
||
| 64 | 'hi' => 'hi|hindi', |
||
| 65 | 'hr' => 'hr|croatian', |
||
| 66 | 'hu' => 'hu|hungarian', |
||
| 67 | 'id' => 'id|indonesian', |
||
| 68 | 'it' => 'it|italian', |
||
| 69 | 'ja' => 'ja|japanese', |
||
| 70 | 'ko' => 'ko|korean', |
||
| 71 | 'ka' => 'ka|georgian', |
||
| 72 | 'lt' => 'lt|lithuanian', |
||
| 73 | 'lv' => 'lv|latvian', |
||
| 74 | 'mk' => 'mk|macedonian', |
||
| 75 | 'mt' => 'mt|maltese', |
||
| 76 | 'ms' => 'ms|malaysian', |
||
| 77 | 'nl' => 'nl([-_][[:alpha:]]{2})?|dutch', |
||
| 78 | 'no' => 'no|norwegian', |
||
| 79 | 'pl' => 'pl|polish', |
||
| 80 | 'pt' => 'pt([-_][[:alpha:]]{2})?|portuguese', |
||
| 81 | 'ro' => 'ro|romanian', |
||
| 82 | 'ru' => 'ru|russian', |
||
| 83 | 'sk' => 'sk|slovak', |
||
| 84 | 'sq' => 'sq|albanian', |
||
| 85 | 'sr' => 'sr|serbian', |
||
| 86 | 'sv' => 'sv|swedish', |
||
| 87 | 'sz' => 'sz|sami', |
||
| 88 | 'sx' => 'sx|sutu', |
||
| 89 | 'th' => 'th|thai', |
||
| 90 | 'ts' => 'ts|tsonga', |
||
| 91 | 'tr' => 'tr|turkish', |
||
| 92 | 'tn' => 'tn|tswana', |
||
| 93 | 'uk' => 'uk|ukrainian', |
||
| 94 | 'ur' => 'ur|urdu', |
||
| 95 | 'vi' => 'vi|vietnamese', |
||
| 96 | 'tw' => 'zh[-_]tw|chinese traditional', |
||
| 97 | 'zh' => 'zh|chinese simplified', |
||
| 98 | 'ji' => 'ji|yiddish', |
||
| 99 | 'zu' => 'zu|zulu' |
||
| 100 | ]; |
||
| 101 | |||
| 102 | if (!isset($code) || !$this->exists($code)) { |
||
| 103 | if (isset($_SESSION['language'])) { |
||
| 104 | $code = $_SESSION['language']; |
||
| 105 | } else { |
||
| 106 | $client = $this->getClientPreference(); |
||
| 107 | |||
| 108 | $code = ($client !== false) ? $client : DEFAULT_LANGUAGE; |
||
| 109 | } |
||
| 110 | } |
||
| 111 | |||
| 112 | $this->set($code); |
||
| 113 | } |
||
| 114 | |||
| 341 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.