| Conditions | 10 |
| Paths | 20 |
| Total Lines | 32 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 110 |
| 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 |
||
| 11 | public function renderOptions($options = false) { |
||
| 12 | $options = $options ? $options : $this->getElement()->getOptions(); |
||
| 13 | $return = ''; |
||
| 14 | foreach ($options as $value=>$atribs) { |
||
| 15 | if (is_string($value) && !isset($atribs['label'])) { |
||
| 16 | $return .= '<optgroup label="' . $value . '">'; |
||
| 17 | $return .= $this->renderOptions($atribs); |
||
| 18 | $return .= '</optgroup>'; |
||
| 19 | } else { |
||
| 20 | $return .= '<option'; |
||
| 21 | |||
| 22 | $label = $atribs['label']; |
||
| 23 | unset ($atribs['label']); |
||
| 24 | |||
| 25 | $atribs['value'] = $value; |
||
| 26 | $selectedValue = $this->getElement()->getValue(); |
||
| 27 | if ($selectedValue === 0 OR $value=== 0) { |
||
| 28 | if ($value === $selectedValue) { |
||
| 29 | $atribs['selected'] = 'selected'; |
||
| 30 | } |
||
| 31 | } elseif ($this->getElement()->getValue() == $value) { |
||
| 32 | $atribs['selected'] = 'selected'; |
||
| 33 | } |
||
| 34 | |||
| 35 | foreach ($atribs as $name=>$value) { |
||
| 36 | $return .= ' ' . $name . '="' . $value . '"'; |
||
| 37 | } |
||
| 38 | $return .= '>'.$label.'</option>'; |
||
| 39 | } |
||
| 40 | } |
||
| 41 | return $return; |
||
| 42 | } |
||
| 43 | |||
| 50 | } |
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.