| Conditions | 11 |
| Paths | 43 |
| Total Lines | 45 |
| Code Lines | 31 |
| Lines | 10 |
| Ratio | 22.22 % |
| Changes | 3 | ||
| 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 |
||
| 51 | public function list_locales($locale) { |
||
| 52 | $locale_names = array(); |
||
| 53 | |||
| 54 | $lang = NULL; |
||
| 55 | $country = NULL; |
||
| 56 | $charset = NULL; |
||
| 57 | $modifier = NULL; |
||
| 58 | |||
| 59 | if ($locale) { |
||
| 60 | if (preg_match("/^(?P<lang>[a-z]{2,3})" // language code |
||
| 61 | ."(?:_(?P<country>[A-Z]{2}))?" // country code |
||
| 62 | ."(?:\.(?P<charset>[-A-Za-z0-9_]+))?" // charset |
||
| 63 | ."(?:@(?P<modifier>[-A-Za-z0-9_]+))?$/", // @ modifier |
||
| 64 | $locale, $matches)) { |
||
| 65 | |||
| 66 | extract($matches); |
||
| 67 | |||
| 68 | View Code Duplication | if ($modifier) { |
|
| 69 | if ($country) { |
||
| 70 | if ($charset) { |
||
| 71 | array_push($locale_names, "${lang}_$country.$charset@$modifier"); |
||
| 72 | } |
||
| 73 | array_push($locale_names, "${lang}_$country@$modifier"); |
||
| 74 | } elseif ($charset) |
||
| 75 | array_push($locale_names, "${lang}.$charset@$modifier"); |
||
| 76 | array_push($locale_names, "$lang@$modifier"); |
||
| 77 | } |
||
| 78 | if ($country) { |
||
| 79 | if ($charset) { |
||
| 80 | array_push($locale_names, "${lang}_$country.$charset"); |
||
| 81 | } |
||
| 82 | array_push($locale_names, "${lang}_$country"); |
||
| 83 | } elseif ($charset) { |
||
| 84 | array_push($locale_names, "${lang}.$charset"); |
||
| 85 | } |
||
| 86 | array_push($locale_names, $lang); |
||
| 87 | } |
||
| 88 | |||
| 89 | // If the locale name doesn't match POSIX style, just include it as-is. |
||
| 90 | if (!in_array($locale, $locale_names)) { |
||
| 91 | array_push($locale_names, $locale); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | return $locale_names; |
||
| 95 | } |
||
| 96 | |||
| 122 |
This check marks private properties in classes that are never used. Those properties can be removed.