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