Conditions | 14 |
Paths | 50 |
Total Lines | 63 |
Code Lines | 42 |
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 |
||
67 | public function description($type, array $attr, $locale='en') |
||
68 | { |
||
69 | $name = $attr['name']; |
||
70 | $brand = isset($attr['brand']) ? $attr['brand'] : null; |
||
71 | |||
72 | switch ($locale) { |
||
73 | case 'da': |
||
74 | case 'dk': |
||
75 | case 'danish': |
||
76 | case 'dansk': |
||
77 | switch ($type) { |
||
78 | case 'article': |
||
79 | $return = substr($attr['body'], 0, 155); |
||
80 | break; |
||
81 | |||
82 | case 'brand': |
||
83 | $return = sprintf('1000vis af RABATTER på %s', $name); |
||
84 | break; |
||
85 | |||
86 | case 'product': |
||
87 | if ($brand) { |
||
88 | $return = sprintf('Aktuelt TILBUD på %s / %s', $name, $brand); |
||
89 | } else { |
||
90 | $return = sprintf('Aktuelt TILBUD på %s', $name); |
||
91 | } |
||
92 | |||
93 | break; |
||
94 | |||
95 | default: |
||
96 | $return = substr($attr['description'], 0, 155); |
||
97 | } |
||
98 | |||
99 | break; |
||
100 | |||
101 | default: |
||
102 | switch ($type) { |
||
103 | case 'article': |
||
104 | $return = substr($attr['body'], 0, 155); |
||
105 | break; |
||
106 | |||
107 | case 'brand': |
||
108 | $return = sprintf('1000s of DISCOUNTS on %s', $name); |
||
109 | break; |
||
110 | |||
111 | case 'product': |
||
112 | if ($brand) { |
||
113 | $return = sprintf('Current DISCOUNTS on %s / %s', $name, $brand); |
||
114 | } else { |
||
115 | $return = sprintf('Current DISCOUNTS on %s', $name); |
||
116 | } |
||
117 | |||
118 | break; |
||
119 | |||
120 | default: |
||
121 | $return = substr($attr['description'], 0, 155); |
||
122 | |||
123 | break; |
||
124 | } |
||
125 | |||
126 | break; |
||
127 | } |
||
128 | |||
129 | return $return; |
||
130 | } |
||
232 |