Conditions | 11 |
Paths | 16 |
Total Lines | 172 |
Code Lines | 129 |
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 |
||
237 | protected function _cleanObjectDatas($object) |
||
238 | { |
||
239 | // phpcs:enable |
||
240 | // Remove $db object property for object |
||
241 | unset($object->db); |
||
242 | unset($object->isextrafieldmanaged); |
||
243 | unset($object->ismultientitymanaged); |
||
244 | unset($object->restrictiononfksoc); |
||
245 | unset($object->table_rowid); |
||
246 | unset($object->pass); |
||
247 | unset($object->pass_indatabase); |
||
248 | |||
249 | // Remove linkedObjects. We should already have and keep only linkedObjectsIds that avoid huge responses |
||
250 | unset($object->linkedObjects); |
||
251 | //unset($object->lines[$i]->linked_objects); // This is the array to create linked object during create |
||
252 | |||
253 | unset($object->fields); |
||
254 | unset($object->oldline); |
||
255 | |||
256 | unset($object->error); |
||
257 | unset($object->errors); |
||
258 | unset($object->errorhidden); |
||
259 | |||
260 | unset($object->ref_previous); |
||
261 | unset($object->ref_next); |
||
262 | unset($object->imgWidth); |
||
263 | unset($object->imgHeight); |
||
264 | unset($object->barcode_type_code); |
||
265 | unset($object->barcode_type_label); |
||
266 | |||
267 | unset($object->mode_reglement); // We use mode_reglement_id now |
||
268 | unset($object->cond_reglement); // We use cond_reglement_id now |
||
269 | unset($object->note); // We use note_public or note_private now |
||
270 | unset($object->contact); // We use contact_id now |
||
271 | unset($object->thirdparty); // We use thirdparty_id or fk_soc or socid now |
||
272 | |||
273 | unset($object->projet); // Should be fk_project |
||
274 | unset($object->project); // Should be fk_project |
||
275 | unset($object->fk_projet); // Should be fk_project |
||
276 | unset($object->author); // Should be fk_user_author |
||
277 | unset($object->timespent_old_duration); |
||
278 | unset($object->timespent_id); |
||
279 | unset($object->timespent_duration); |
||
280 | unset($object->timespent_date); |
||
281 | unset($object->timespent_datehour); |
||
282 | unset($object->timespent_withhour); |
||
283 | unset($object->timespent_fk_user); |
||
284 | unset($object->timespent_note); |
||
285 | unset($object->fk_delivery_address); |
||
286 | unset($object->model_pdf); |
||
287 | unset($object->sendtoid); |
||
288 | unset($object->name_bis); |
||
289 | unset($object->newref); |
||
290 | unset($object->oldref); |
||
291 | unset($object->alreadypaid); |
||
292 | unset($object->openid); |
||
293 | unset($object->fk_bank); |
||
294 | unset($object->showphoto_on_popup); |
||
295 | unset($object->nb); |
||
296 | unset($object->nbphoto); |
||
297 | unset($object->output); |
||
298 | unset($object->tpl); |
||
299 | //unset($object->libelle); |
||
300 | |||
301 | unset($object->stats_propale); |
||
302 | unset($object->stats_commande); |
||
303 | unset($object->stats_contrat); |
||
304 | unset($object->stats_facture); |
||
305 | unset($object->stats_commande_fournisseur); |
||
306 | unset($object->stats_reception); |
||
307 | unset($object->stats_mrptoconsume); |
||
308 | unset($object->stats_mrptoproduce); |
||
309 | |||
310 | unset($object->origin_object); |
||
311 | unset($object->origin); |
||
312 | unset($object->element); |
||
313 | unset($object->element_for_permission); |
||
314 | unset($object->fk_element); |
||
315 | unset($object->table_element); |
||
316 | unset($object->table_element_line); |
||
317 | unset($object->class_element_line); |
||
318 | unset($object->picto); |
||
319 | unset($object->linked_objects); |
||
320 | |||
321 | unset($object->fieldsforcombobox); |
||
322 | unset($object->regeximgext); |
||
323 | |||
324 | unset($object->skip_update_total); |
||
325 | unset($object->context); |
||
326 | unset($object->next_prev_filter); |
||
327 | |||
328 | unset($object->region); |
||
329 | unset($object->region_code); |
||
330 | unset($object->country); |
||
331 | unset($object->state); |
||
332 | unset($object->state_code); |
||
333 | unset($object->fk_departement); |
||
334 | unset($object->departement); |
||
335 | unset($object->departement_code); |
||
336 | |||
337 | unset($object->libelle_statut); |
||
338 | unset($object->libelle_paiement); |
||
339 | unset($object->labelStatus); |
||
340 | unset($object->labelStatusShort); |
||
341 | |||
342 | unset($object->actionmsg); |
||
343 | unset($object->actionmsg2); |
||
344 | |||
345 | unset($object->prefix_comm); |
||
346 | |||
347 | if (!isset($object->table_element) || $object->table_element != 'ticket') { |
||
348 | unset($object->comments); |
||
349 | } |
||
350 | |||
351 | // Remove the $oldcopy property because it is not supported by the JSON |
||
352 | // encoder. The following error is generated when trying to serialize |
||
353 | // it: "Error encoding/decoding JSON: Type is not supported" |
||
354 | // Note: Event if this property was correctly handled by the JSON |
||
355 | // encoder, it should be ignored because keeping it would let the API |
||
356 | // have a very strange behavior: calling PUT and then GET on the same |
||
357 | // resource would give different results: |
||
358 | // PUT /objects/{id} -> returns object with oldcopy = previous version of the object |
||
359 | // GET /objects/{id} -> returns object with oldcopy empty |
||
360 | unset($object->oldcopy); |
||
361 | |||
362 | // If object has lines, remove $db property |
||
363 | if (isset($object->lines) && is_array($object->lines) && count($object->lines) > 0) { |
||
364 | $nboflines = count($object->lines); |
||
365 | for ($i = 0; $i < $nboflines; $i++) { |
||
366 | $this->_cleanObjectDatas($object->lines[$i]); |
||
367 | |||
368 | unset($object->lines[$i]->contact); |
||
369 | unset($object->lines[$i]->contact_id); |
||
370 | unset($object->lines[$i]->country); |
||
371 | unset($object->lines[$i]->country_id); |
||
372 | unset($object->lines[$i]->country_code); |
||
373 | unset($object->lines[$i]->mode_reglement_id); |
||
374 | unset($object->lines[$i]->mode_reglement_code); |
||
375 | unset($object->lines[$i]->mode_reglement); |
||
376 | unset($object->lines[$i]->cond_reglement_id); |
||
377 | unset($object->lines[$i]->cond_reglement_code); |
||
378 | unset($object->lines[$i]->cond_reglement); |
||
379 | unset($object->lines[$i]->fk_delivery_address); |
||
380 | unset($object->lines[$i]->fk_projet); |
||
381 | unset($object->lines[$i]->fk_project); |
||
382 | unset($object->lines[$i]->thirdparty); |
||
383 | unset($object->lines[$i]->user); |
||
384 | unset($object->lines[$i]->model_pdf); |
||
385 | unset($object->lines[$i]->note_public); |
||
386 | unset($object->lines[$i]->note_private); |
||
387 | unset($object->lines[$i]->fk_incoterms); |
||
388 | unset($object->lines[$i]->label_incoterms); |
||
389 | unset($object->lines[$i]->location_incoterms); |
||
390 | unset($object->lines[$i]->name); |
||
391 | unset($object->lines[$i]->lastname); |
||
392 | unset($object->lines[$i]->firstname); |
||
393 | unset($object->lines[$i]->civility_id); |
||
394 | unset($object->lines[$i]->fk_multicurrency); |
||
395 | unset($object->lines[$i]->multicurrency_code); |
||
396 | unset($object->lines[$i]->shipping_method_id); |
||
397 | } |
||
398 | } |
||
399 | |||
400 | if (!empty($object->thirdparty) && is_object($object->thirdparty)) { |
||
401 | $this->_cleanObjectDatas($object->thirdparty); |
||
402 | } |
||
403 | |||
404 | if (!empty($object->product) && is_object($object->product)) { |
||
405 | $this->_cleanObjectDatas($object->product); |
||
406 | } |
||
407 | |||
408 | return $object; |
||
409 | } |
||
429 |