| Conditions | 12 |
| Paths | 320 |
| Total Lines | 54 |
| Code Lines | 37 |
| 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 |
||
| 65 | public function defaultRender() |
||
| 66 | { |
||
| 67 | $required = $this->has('required'); |
||
| 68 | $elementOptions = $this->getOptions(); |
||
| 69 | $elementValue = $this->getValue(); |
||
| 70 | if (!is_array($elementValue)) { |
||
| 71 | $elementValue = (array) $elementValue; |
||
| 72 | } |
||
| 73 | $extra = ($this->getExtra() != '' ? " " . $this->getExtra() : ''); |
||
| 74 | |||
| 75 | $elementName = $this->getName(); |
||
| 76 | $elementId = $elementName; |
||
| 77 | if (count($elementOptions) > 1 && substr($elementName, -2, 2) !== '[]') { |
||
| 78 | $elementName = $elementName . '[]'; |
||
| 79 | $this->setName($elementName); |
||
| 80 | // If required is set, all checkboxes will be required by the browser, |
||
| 81 | // which is not usually useful. We stash the value of required above |
||
| 82 | // and unset now. We restore it before return so JS validation will still |
||
| 83 | // be triggered. This is only a problem if there is more than one checkbox. |
||
| 84 | $this->remove('required'); |
||
| 85 | } |
||
| 86 | |||
| 87 | $ret = ""; |
||
| 88 | $inline = (bool) $this->get(':inline', false); |
||
| 89 | if ($inline) { |
||
| 90 | $ret .= '<div class="input-group">'; |
||
| 91 | } |
||
| 92 | $idCount = 0; |
||
| 93 | foreach ($elementOptions as $value => $name) { |
||
| 94 | $this->remove('checked'); |
||
| 95 | if (!empty($elementValue) && in_array($value, $elementValue)) { |
||
|
|
|||
| 96 | $this->set('checked'); |
||
| 97 | } |
||
| 98 | $this->set('value', $value); |
||
| 99 | ++$idCount; |
||
| 100 | $this->set('id', $elementId . $idCount); |
||
| 101 | if ($inline) { |
||
| 102 | $ret .= '<label class="checkbox-inline">'; |
||
| 103 | $ret .= '<input ' . $this->renderAttributeString() . $extra . ">" . $name . "\n"; |
||
| 104 | $ret .= "</label>\n"; |
||
| 105 | } else { |
||
| 106 | $ret .= "<div class=\"checkbox\">\n<label>"; |
||
| 107 | $ret .= '<input ' . $this->renderAttributeString() . $extra . '>' . $name . "\n"; |
||
| 108 | $ret .= "</label>\n</div>\n"; |
||
| 109 | } |
||
| 110 | |||
| 111 | } |
||
| 112 | if ($required) { |
||
| 113 | $this->set('required'); |
||
| 114 | } |
||
| 115 | if ($inline) { |
||
| 116 | $ret .= '</div>'; |
||
| 117 | } |
||
| 118 | return $ret; |
||
| 119 | } |
||
| 150 |