| Conditions | 15 |
| Paths | 43 |
| Total Lines | 45 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 77 | public function negotiateLanguage() |
||
| 78 | { |
||
| 79 | $matches = $this->getMatchesFromAcceptedLanguages(); |
||
| 80 | foreach ($matches as $key => $q) { |
||
| 81 | if (!empty($this->supportedLanguages[$key])) { |
||
| 82 | return $key; |
||
| 83 | } |
||
| 84 | |||
| 85 | if ($this->use_intl) { |
||
| 86 | $key = Locale::canonicalize($key); |
||
| 87 | } |
||
| 88 | |||
| 89 | // Search for acceptable locale by 'regional' => 'af_ZA' or 'lang' => 'af-ZA' match. |
||
| 90 | foreach ( $this->supportedLanguages as $key_supported => $locale ) { |
||
| 91 | if ( (isset($locale['regional']) && $locale['regional'] == $key) || (isset($locale['lang']) && $locale['lang'] == $key) ) { |
||
| 92 | return $key_supported; |
||
| 93 | } |
||
| 94 | } |
||
| 95 | } |
||
| 96 | // If any (i.e. "*") is acceptable, return the first supported format |
||
| 97 | if (isset($matches['*'])) { |
||
| 98 | reset($this->supportedLanguages); |
||
| 99 | |||
| 100 | return key($this->supportedLanguages); |
||
| 101 | } |
||
| 102 | |||
| 103 | if ($this->use_intl && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
||
| 104 | $http_accept_language = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']); |
||
| 105 | |||
| 106 | if (!empty($this->supportedLanguages[$http_accept_language])) { |
||
| 107 | return $http_accept_language; |
||
| 108 | } |
||
| 109 | } |
||
| 110 | |||
| 111 | if ($this->request->server('REMOTE_HOST')) { |
||
| 112 | $remote_host = explode('.', $this->request->server('REMOTE_HOST')); |
||
| 113 | $lang = strtolower(end($remote_host)); |
||
| 114 | |||
| 115 | if (!empty($this->supportedLanguages[$lang])) { |
||
| 116 | return $lang; |
||
| 117 | } |
||
| 118 | } |
||
| 119 | |||
| 120 | return $this->defaultLocale; |
||
| 121 | } |
||
| 122 | |||
| 178 |