Conditions | 12 |
Paths | 34 |
Total Lines | 48 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
68 | public function description($type, array $attr, $locale='en') |
||
69 | { |
||
70 | $name = $attr['name']; |
||
71 | $brand = isset($attr['brand']) ? $attr['brand'] : null; |
||
72 | |||
73 | $return = $name; |
||
74 | |||
75 | switch ($locale) { |
||
76 | case 'en': |
||
77 | case 'english': |
||
78 | switch ($type) { |
||
79 | case 'brand': |
||
80 | $return = sprintf('1000s of DISCOUNTS on %s', $name); |
||
81 | break; |
||
82 | |||
83 | case 'product': |
||
84 | if ($brand) { |
||
85 | $return = sprintf('Current DISCOUNTS on %s / %s', $name, $brand); |
||
86 | } else { |
||
87 | $return = sprintf('Current DISCOUNTS on %s', $name); |
||
88 | } |
||
89 | |||
90 | break; |
||
91 | } |
||
92 | |||
93 | break; |
||
94 | |||
95 | case 'da': |
||
96 | case 'danish': |
||
97 | switch ($type) { |
||
98 | case 'brand': |
||
99 | $return = sprintf('1000vis af RABATTER på %s', $name); |
||
100 | break; |
||
101 | |||
102 | case 'product': |
||
103 | if ($brand) { |
||
104 | $return = sprintf('Aktuelt TILBUD på %s / %s', $name, $brand); |
||
105 | } else { |
||
106 | $return = sprintf('Aktuelt TILBUD på %s', $name); |
||
107 | } |
||
108 | |||
109 | break; |
||
110 | } |
||
111 | |||
112 | break; |
||
113 | } |
||
114 | |||
115 | return $return; |
||
116 | } |
||
169 |