Conditions | 20 |
Paths | 9 |
Total Lines | 121 |
Code Lines | 81 |
Lines | 81 |
Ratio | 66.94 % |
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) |
||
150 | { |
||
151 | $fields = $this->getFields(); |
||
152 | $instance = $this->getModelInstance(); |
||
153 | $output = ''; |
||
154 | |||
155 | switch ($type) { |
||
156 | View Code Duplication | case 'form-create': |
|
157 | foreach ($fields as $f) { |
||
158 | $ucF = ucfirst($f); |
||
159 | |||
160 | $input_attr = [ |
||
161 | 'class' => 'form-control', |
||
162 | 'id' => 'createItem'.$f, |
||
163 | 'name' => $f, |
||
164 | ]; |
||
165 | |||
166 | $output .= '<fieldset class="form-group">'; |
||
167 | |||
168 | $output .= '<label for="'.$input_attr['id'].'">'.$ucF.'</label>'; |
||
169 | |||
170 | if ($this->fieldHelper->isIdField($f)) { |
||
171 | $input_attr['type'] = 'select'; |
||
172 | |||
173 | $output .= '<select '; |
||
174 | foreach ($input_attr as $attr => $value) { |
||
175 | $output .= "{$attr}='{$value}'"; |
||
176 | } |
||
177 | |||
178 | $relation = $this->getRelatedModel($f); |
||
179 | $output .= '>'; |
||
180 | |||
181 | $output .= $this->getRelatedOptions($relation); |
||
182 | |||
183 | $output .= '</select>'; |
||
184 | } else { |
||
185 | $input_attr['type'] = 'text'; |
||
186 | |||
187 | $output .= '<input '; |
||
188 | foreach ($input_attr as $attr => $value) { |
||
189 | $output .= "{$attr}='{$value}'"; |
||
190 | } |
||
191 | $output .= '>'; |
||
192 | } |
||
193 | |||
194 | $output .= '</fieldset>'; |
||
195 | } |
||
196 | break; |
||
197 | View Code Duplication | case 'form-edit': |
|
198 | foreach ($fields as $f) { |
||
199 | $ucF = ucfirst($f); |
||
200 | |||
201 | $input_attr = [ |
||
202 | 'class' => 'form-control', |
||
203 | 'id' => 'editItem'.$ucF, |
||
204 | 'name' => $f, |
||
205 | ]; |
||
206 | |||
207 | $output .= '<fieldset class="form-group">'; |
||
208 | |||
209 | $output .= '<label for="'.$input_attr['id'].'">'.$ucF.'</label>'; |
||
210 | |||
211 | if ($this->fieldHelper->isIdField($f)) { |
||
212 | $input_attr['type'] = 'select'; |
||
213 | |||
214 | $output .= '<select '; |
||
215 | foreach ($input_attr as $attr => $value) { |
||
216 | $output .= "{$attr}='{$value}'"; |
||
217 | } |
||
218 | |||
219 | $relation = $this->getRelatedModel($f); |
||
220 | $output .= '>'; |
||
221 | |||
222 | $output .= $this->getRelatedOptions($relation); |
||
223 | $output .= '</select>'; |
||
224 | } else { |
||
225 | $input_attr['type'] = 'text'; |
||
226 | |||
227 | $output .= '<input '; |
||
228 | foreach ($input_attr as $attr => $value) { |
||
229 | $output .= "{$attr}='{$value}'"; |
||
230 | } |
||
231 | $output .= '>'; |
||
232 | } |
||
233 | |||
234 | $output .= '</fieldset>'; |
||
235 | } |
||
236 | break; |
||
237 | case 'table-headings': |
||
238 | foreach ($fields as $f) { |
||
239 | $output .= '<th>'.ucfirst($f).'</th>'; |
||
240 | } |
||
241 | break; |
||
242 | case 'table-content': |
||
243 | foreach ($fields as $f) { |
||
244 | if ($this->fieldHelper->isIdField($f)) { |
||
245 | $display = $this->getRelatedDisplay($f); |
||
246 | $output .= '<td>'.$display.'</td>'; |
||
247 | } else { |
||
248 | $output .= '<td>'.$this->instance->$f.'</td>'; |
||
249 | } |
||
250 | } |
||
251 | break; |
||
252 | // JavaScript Variables |
||
253 | case 'js-var': |
||
254 | foreach ($fields as $f) { |
||
255 | $output .= 'var '.$f.' = '.$this->instance->$f.'; '; |
||
256 | } |
||
257 | break; |
||
258 | case 'js-modal-create': |
||
259 | foreach ($fields as $f) { |
||
260 | $output .= '"'.$f.'": $(\'#createItem'.$f.'\').val(), '; |
||
261 | } |
||
262 | break; |
||
263 | default: |
||
264 | return; |
||
265 | break; |
||
266 | } |
||
267 | |||
268 | echo $output; |
||
269 | } |
||
270 | |||
369 |
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.