| Conditions | 15 |
| Paths | 84 |
| Total Lines | 57 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 9 | public function title($type, array $attr, $locale='en') |
||
| 10 | { |
||
| 11 | $name = $attr['name']; |
||
| 12 | $brand = isset($attr['brand']) ? $attr['brand'] : null; |
||
| 13 | $site = isset($attr['site']) ? $attr['site'] : null; |
||
| 14 | |||
| 15 | $return = $name; |
||
| 16 | |||
| 17 | switch ($locale) { |
||
| 18 | case 'en': |
||
| 19 | case 'english': |
||
| 20 | switch ($type) { |
||
| 21 | case 'article': |
||
| 22 | $return = sprintf('%s | %s', $name, $site); |
||
| 23 | break; |
||
| 24 | |||
| 25 | case 'brand': |
||
| 26 | $return = sprintf('1000s of DISCOUNTS on %s', $name); |
||
| 27 | break; |
||
| 28 | |||
| 29 | case 'product': |
||
| 30 | if ($brand) { |
||
| 31 | $return = sprintf('NEW, %s by %s', $name, $brand); |
||
| 32 | } else { |
||
| 33 | $return = sprintf('NEW, %s by %s', $name, $brand); |
||
| 34 | } |
||
| 35 | |||
| 36 | break; |
||
| 37 | } |
||
| 38 | |||
| 39 | break; |
||
| 40 | |||
| 41 | case 'da': |
||
| 42 | case 'danish': |
||
| 43 | switch ($type) { |
||
| 44 | case 'article': |
||
| 45 | $return = sprintf('%s | %s', $name, $site); |
||
| 46 | break; |
||
| 47 | |||
| 48 | case 'brand': |
||
| 49 | $return = sprintf('1000vis af RABATTER på %s', $name); |
||
| 50 | break; |
||
| 51 | |||
| 52 | case 'product': |
||
| 53 | if ($brand) { |
||
| 54 | $return = sprintf('NYT, %s fra %s', $name, $brand); |
||
| 55 | } else { |
||
| 56 | $return = sprintf('NYT, %s', $name); |
||
| 57 | } |
||
| 58 | |||
| 59 | break; |
||
| 60 | } |
||
| 61 | |||
| 62 | break; |
||
| 63 | } |
||
| 64 | |||
| 65 | return $return; |
||
| 66 | } |
||
| 169 |