| Conditions | 12 |
| Paths | 26 |
| Total Lines | 42 |
| Code Lines | 21 |
| 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 |
||
| 53 | public function negotiateLanguage() |
||
| 54 | { |
||
| 55 | $matches = $this->getMatchesFromAcceptedLanguages(); |
||
| 56 | foreach ($matches as $key => $q) { |
||
| 57 | if (!empty($this->supportedLanguages[$key])) { |
||
| 58 | return $key; |
||
| 59 | } |
||
| 60 | |||
| 61 | // Search for acceptable locale by 'regional' => 'af_ZA' or 'lang' => 'af-ZA' match. |
||
| 62 | foreach ( $this->supportedLanguages as $key_supported => $locale ) { |
||
| 63 | if ( $locale['regional'] == $key || $locale['lang'] == $key ) { |
||
| 64 | return $key_supported; |
||
| 65 | } |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | // If any (i.e. "*") is acceptable, return the first supported format |
||
| 70 | if (isset($matches['*'])) { |
||
| 71 | reset($this->supportedLanguages); |
||
| 72 | |||
| 73 | return key($this->supportedLanguages); |
||
| 74 | } |
||
| 75 | |||
| 76 | if (class_exists('Locale') && !empty($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
||
| 77 | $http_accept_language = Locale::acceptFromHttp($_SERVER['HTTP_ACCEPT_LANGUAGE']); |
||
| 78 | |||
| 79 | if (!empty($this->supportedLanguages[$http_accept_language])) { |
||
| 80 | return $http_accept_language; |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | if ($this->request->server('REMOTE_HOST')) { |
||
| 85 | $remote_host = explode('.', $this->request->server('REMOTE_HOST')); |
||
| 86 | $lang = strtolower(end($remote_host)); |
||
| 87 | |||
| 88 | if (!empty($this->supportedLanguages[$lang])) { |
||
| 89 | return $lang; |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 93 | return $this->defaultLocale; |
||
| 94 | } |
||
| 95 | |||
| 151 |