| Conditions | 12 |
| Paths | 228 |
| Total Lines | 43 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 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 |
||
| 30 | public function render() |
||
| 31 | { |
||
| 32 | $ret = ''; |
||
| 33 | $ele_name = $this->getName(); |
||
| 34 | $ele_title = $this->getTitle(); |
||
| 35 | $ele_value = $this->getValue(); |
||
| 36 | $ele_options = $this->getOptions(); |
||
| 37 | $ele_extra = $this->getExtra(); |
||
| 38 | $ele_delimeter = empty($this->columns) ? $this->getDelimeter() : ''; |
||
| 39 | if (!empty($this->columns)) { |
||
| 40 | $ret .= '<table class="table table-bordered"><tr>'; |
||
| 41 | } |
||
| 42 | $i = 0; |
||
| 43 | $id_ele = 0; |
||
| 44 | foreach ($ele_options as $value => $name) { |
||
| 45 | ++$id_ele; |
||
| 46 | if (!empty($this->columns)) { |
||
| 47 | if ($i % $this->columns == 0) { |
||
| 48 | $ret .= '<tr>'; |
||
| 49 | } |
||
| 50 | $ret .= '<td class="radio">'; |
||
| 51 | } |
||
| 52 | $ret .= '<input type="radio" name="'.$ele_name.'" id="'.$ele_name.'['.$value.']'.$id_ele.'" title = "'.htmlspecialchars($ele_title, ENT_QUOTES).'" value="'.htmlspecialchars($value, ENT_QUOTES).'"'; |
||
| 53 | if (isset($ele_value) && $value == $ele_value) { |
||
| 54 | $ret .= ' checked="checked"'; |
||
| 55 | } |
||
| 56 | $ret .= $ele_extra.' />'."<label name='xolb_{$ele_name}' for='".$ele_name.'['.$value.']'.$id_ele."'><span><span></span></span>".$name.'</label>'.$ele_delimeter; |
||
| 57 | if (!empty($this->columns)) { |
||
| 58 | $ret .= '</td>'; |
||
| 59 | if (++$i % $this->columns == 0) { |
||
| 60 | $ret .= '</tr>'; |
||
| 61 | } |
||
| 62 | } |
||
| 63 | } |
||
| 64 | if (!empty($this->columns)) { |
||
| 65 | if ($span = $i % $this->columns) { |
||
| 66 | $ret .= '<td colspan="'.($this->columns - $span).'"></td></tr>'; |
||
| 67 | } |
||
| 68 | $ret .= '</table>'; |
||
| 69 | } |
||
| 70 | |||
| 71 | return $ret; |
||
| 72 | } |
||
| 73 | } |
||
| 74 |
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.