| Conditions | 10 |
| Paths | 64 |
| Total Lines | 47 |
| Code Lines | 21 |
| 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 |
||
| 129 | public function render() |
||
| 130 | { |
||
| 131 | // open the html select tag |
||
| 132 | $html = ''; |
||
| 133 | $html .= '<select '; |
||
| 134 | $html .= (bool) $this->name ? 'name="' . $this->name . '"' : null; |
||
| 135 | $html .= (bool) $this->id ? 'id="' . $this->id . '"' : null; |
||
| 136 | $html .= (bool) $this->class ? 'class="' . $this->class . '"' : null; |
||
| 137 | $html .= (bool) $this->size ? 'size="' . $this->size . '"' : null; |
||
| 138 | $html .= '>'; |
||
| 139 | |||
| 140 | /** |
||
| 141 | * This handles the default value setting via the options array key "selected". |
||
| 142 | * It grabs the first element in the options array, which keyname should be 'selected' |
||
| 143 | * and then removes it, setting its value to $this->default. |
||
| 144 | * |
||
| 145 | * The check for empty($this->default) is important, because the default value might already |
||
| 146 | * be set via setDefaultValue(). Such a scenario is given, when the form is generated via array. |
||
| 147 | * The array would contain options['selected'] with an default value, but the actual default |
||
| 148 | * value is incomming via setDefaultValue(). |
||
| 149 | * |
||
| 150 | * Note: If the options array is incomming via a formgenerator: the generator has already performed this step! |
||
| 151 | * $this->setDefault(options['selected']); |
||
| 152 | */ |
||
| 153 | if ($this->options['selected'] !== null and empty($this->default)) { |
||
| 154 | $this->default = $this->options['selected']; |
||
| 155 | unset($this->options['selected']); |
||
| 156 | } |
||
| 157 | |||
| 158 | if (empty($this->options) === false) { |
||
| 159 | // loop over all selectfield options |
||
| 160 | foreach ($this->options as $key => $value) { |
||
| 161 | if ($this->withValuesAsKeys === true) { |
||
| 162 | $html .= $this->renderOptionTag($value, $value); |
||
| 163 | } else { |
||
| 164 | $html .= $this->renderOptionTag($key, $value); |
||
| 165 | } |
||
| 166 | } |
||
| 167 | } else { |
||
| 168 | $html .= '<option value="0">No Options given.</option>'; |
||
| 169 | } |
||
| 170 | |||
| 171 | // close the html select tag |
||
| 172 | $html .= '</select>'; |
||
| 173 | |||
| 174 | return $html; |
||
| 175 | } |
||
| 176 | |||
| 197 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.