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