| Conditions | 14 |
| Paths | 14 |
| Total Lines | 75 |
| Code Lines | 52 |
| Lines | 38 |
| Ratio | 50.67 % |
| 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 |
||
| 149 | public function renderFields($type, $fields = []) |
||
| 150 | { |
||
| 151 | if (empty($fields)) { |
||
| 152 | $fields = $this->getFields(); |
||
| 153 | } |
||
| 154 | $output = ''; |
||
| 155 | |||
| 156 | switch ($type) { |
||
| 157 | case 'form-create': |
||
| 158 | $output .= $this->fieldHelper->formCreate($fields); |
||
| 159 | break; |
||
| 160 | case 'form-edit': |
||
| 161 | View Code Duplication | foreach ($fields as $f) { |
|
| 162 | $ucF = ucfirst($f); |
||
| 163 | |||
| 164 | $input_attr = [ |
||
| 165 | 'class' => 'form-control', |
||
| 166 | 'id' => 'editItem'.$ucF, |
||
| 167 | 'name' => $f, |
||
| 168 | ]; |
||
| 169 | |||
| 170 | $output .= '<fieldset class="form-group">'; |
||
| 171 | |||
| 172 | $output .= '<label for="'.$input_attr['id'].'">'.$ucF.'</label>'; |
||
| 173 | |||
| 174 | if ($this->fieldHelper->isIdField($f)) { |
||
| 175 | $input_attr['type'] = 'select'; |
||
| 176 | |||
| 177 | $output .= '<select '; |
||
| 178 | foreach ($input_attr as $attr => $value) { |
||
| 179 | $output .= "{$attr}='{$value}'"; |
||
| 180 | } |
||
| 181 | |||
| 182 | $relation = $this->getRelatedModel($f); |
||
| 183 | $output .= '>'; |
||
| 184 | |||
| 185 | $output .= $this->getRelatedOptions($relation); |
||
| 186 | $output .= '</select>'; |
||
| 187 | } else { |
||
| 188 | $input_attr['type'] = 'text'; |
||
| 189 | |||
| 190 | $output .= '<input '; |
||
| 191 | foreach ($input_attr as $attr => $value) { |
||
| 192 | $output .= "{$attr}='{$value}'"; |
||
| 193 | } |
||
| 194 | $output .= '>'; |
||
| 195 | } |
||
| 196 | |||
| 197 | $output .= '</fieldset>'; |
||
| 198 | } |
||
| 199 | break; |
||
| 200 | case 'table-headings': |
||
| 201 | $output .= $this->fieldHelper->tableHeadings($fields); |
||
| 202 | break; |
||
| 203 | case 'table-content': |
||
| 204 | $output .= $this->fieldHelper->tableContent($fields, $this->instance); |
||
| 205 | break; |
||
| 206 | // JavaScript Variables |
||
| 207 | case 'js-var': |
||
| 208 | foreach ($fields as $f) { |
||
| 209 | $output .= 'var '.$f.' = '.$this->instance->$f.'; '; |
||
| 210 | } |
||
| 211 | break; |
||
| 212 | case 'js-modal-create': |
||
| 213 | foreach ($fields as $f) { |
||
| 214 | $output .= '"'.$f.'": $(\'#createItem'.$f.'\').val(), '; |
||
| 215 | } |
||
| 216 | break; |
||
| 217 | default: |
||
| 218 | return; |
||
| 219 | break; |
||
| 220 | } |
||
| 221 | |||
| 222 | echo $output; |
||
| 223 | } |
||
| 224 | |||
| 323 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.