Conditions | 10 |
Paths | 20 |
Total Lines | 32 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 110 |
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 |
||
12 | public function renderOptions($options = false) |
||
13 | { |
||
14 | $options = $options ? $options : $this->getElement()->getOptions(); |
||
15 | $return = ''; |
||
16 | foreach ($options as $value=>$atribs) { |
||
17 | if (is_string($value) && !isset($atribs['label'])) { |
||
18 | $return .= '<optgroup label="' . $value . '">'; |
||
19 | $return .= $this->renderOptions($atribs); |
||
20 | $return .= '</optgroup>'; |
||
21 | } else { |
||
22 | $return .= '<option'; |
||
23 | |||
24 | $label = $atribs['label']; |
||
25 | unset($atribs['label']); |
||
26 | |||
27 | $atribs['value'] = $value; |
||
28 | $selectedValue = $this->getElement()->getValue(); |
||
29 | if ($selectedValue === 0 or $value === 0) { |
||
30 | if ($value === $selectedValue) { |
||
31 | $atribs['selected'] = 'selected'; |
||
32 | } |
||
33 | } elseif ($this->getElement()->getValue() == $value) { |
||
34 | $atribs['selected'] = 'selected'; |
||
35 | } |
||
36 | |||
37 | foreach ($atribs as $name=>$value) { |
||
38 | $return .= ' ' . $name . '="' . $value . '"'; |
||
39 | } |
||
40 | $return .= '>' . $label . '</option>'; |
||
41 | } |
||
42 | } |
||
43 | return $return; |
||
44 | } |
||
52 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.