Conditions | 9 |
Paths | 349 |
Total Lines | 182 |
Code Lines | 65 |
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 |
||
353 | public function saveItem( \Aimeos\MShop\Common\Item\Iface $item, $fetch = true ) |
||
354 | { |
||
355 | self::checkClass( '\\Aimeos\\MShop\\Customer\\Item\\Iface', $item ); |
||
356 | |||
357 | if( !$item->isModified() ) |
||
358 | { |
||
359 | $item = $this->savePropertyItems( $item, 'customer' ); |
||
360 | $item = $this->saveAddressItems( $item, 'customer' ); |
||
1 ignored issue
–
show
|
|||
361 | return $this->saveListItems( $item, 'customer' ); |
||
362 | } |
||
363 | |||
364 | $context = $this->getContext(); |
||
365 | $dbm = $context->getDatabaseManager(); |
||
366 | $dbname = $this->getResourceName(); |
||
367 | $conn = $dbm->acquire( $dbname ); |
||
368 | |||
369 | try |
||
370 | { |
||
371 | $id = $item->getId(); |
||
372 | $billingAddress = $item->getPaymentAddress(); |
||
1 ignored issue
–
show
|
|||
373 | |||
374 | if( $id === null ) |
||
375 | { |
||
376 | /** mshop/customer/manager/typo3/insert |
||
377 | * Inserts a new customer record into the database table |
||
378 | * |
||
379 | * Items with no ID yet (i.e. the ID is NULL) will be created in |
||
380 | * the database and the newly created ID retrieved afterwards |
||
381 | * using the "newid" SQL statement. |
||
382 | * |
||
383 | * The SQL statement must be a string suitable for being used as |
||
384 | * prepared statement. It must include question marks for binding |
||
385 | * the values from the customer item to the statement before they are |
||
386 | * sent to the database server. The number of question marks must |
||
387 | * be the same as the number of columns listed in the INSERT |
||
388 | * statement. The order of the columns must correspond to the |
||
389 | * order in the saveItems() method, so the correct values are |
||
390 | * bound to the columns. |
||
391 | * |
||
392 | * The SQL statement should conform to the ANSI standard to be |
||
393 | * compatible with most relational database systems. This also |
||
394 | * includes using double quotes for table and column names. |
||
395 | * |
||
396 | * @param string SQL statement for inserting records |
||
397 | * @since 2014.03 |
||
398 | * @category Developer |
||
399 | * @see mshop/customer/manager/typo3/update |
||
400 | * @see mshop/customer/manager/typo3/newid |
||
401 | * @see mshop/customer/manager/typo3/delete |
||
402 | * @see mshop/customer/manager/typo3/search |
||
403 | * @see mshop/customer/manager/typo3/count |
||
404 | */ |
||
405 | $path = 'mshop/customer/manager/typo3/insert'; |
||
406 | } |
||
407 | else |
||
408 | { |
||
409 | /** mshop/customer/manager/typo3/update |
||
410 | * Updates an existing customer record in the database |
||
411 | * |
||
412 | * Items which already have an ID (i.e. the ID is not NULL) will |
||
413 | * be updated in the database. |
||
414 | * |
||
415 | * The SQL statement must be a string suitable for being used as |
||
416 | * prepared statement. It must include question marks for binding |
||
417 | * the values from the customer item to the statement before they are |
||
418 | * sent to the database server. The order of the columns must |
||
419 | * correspond to the order in the saveItems() method, so the |
||
420 | * correct values are bound to the columns. |
||
421 | * |
||
422 | * The SQL statement should conform to the ANSI standard to be |
||
423 | * compatible with most relational database systems. This also |
||
424 | * includes using double quotes for table and column names. |
||
425 | * |
||
426 | * @param string SQL statement for updating records |
||
427 | * @since 2014.03 |
||
428 | * @category Developer |
||
429 | * @see mshop/customer/manager/typo3/insert |
||
430 | * @see mshop/customer/manager/typo3/newid |
||
431 | * @see mshop/customer/manager/typo3/delete |
||
432 | * @see mshop/customer/manager/typo3/search |
||
433 | * @see mshop/customer/manager/typo3/count |
||
434 | */ |
||
435 | $path = 'mshop/customer/manager/typo3/update'; |
||
436 | } |
||
437 | |||
438 | $stmt = $this->getCachedStatement( $conn, $path ); |
||
439 | |||
440 | $address = $billingAddress->getAddress1(); |
||
441 | |||
442 | if( ( $part = $billingAddress->getAddress2() ) != '' ) { |
||
443 | $address .= ' ' . $part; |
||
444 | } |
||
445 | |||
446 | if( ( $part = $billingAddress->getAddress3() ) != '' ) { |
||
447 | $address .= ' ' . $part; |
||
448 | } |
||
449 | |||
450 | // TYPO3 fe_users.static_info_country is a three letter ISO code instead a two letter one |
||
451 | $stmt->bind( 1, $context->getLocale()->getSiteId(), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
||
452 | $stmt->bind( 2, $item->getLabel() ); |
||
1 ignored issue
–
show
|
|||
453 | $stmt->bind( 3, $item->getCode() ); |
||
1 ignored issue
–
show
|
|||
454 | $stmt->bind( 4, $this->plugins['customer.salutation']->translate( $billingAddress->getSalutation() ), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
||
455 | $stmt->bind( 5, $billingAddress->getCompany() ); |
||
456 | $stmt->bind( 6, $billingAddress->getVatID() ); |
||
457 | $stmt->bind( 7, $billingAddress->getTitle() ); |
||
458 | $stmt->bind( 8, $billingAddress->getFirstname() ); |
||
459 | $stmt->bind( 9, $billingAddress->getLastname() ); |
||
460 | $stmt->bind( 10, $address ); |
||
461 | $stmt->bind( 11, $billingAddress->getPostal() ); |
||
462 | $stmt->bind( 12, $billingAddress->getCity() ); |
||
463 | $stmt->bind( 13, $billingAddress->getState() ); |
||
464 | $stmt->bind( 14, $billingAddress->getLanguageId() ); |
||
465 | $stmt->bind( 15, $billingAddress->getTelephone() ); |
||
466 | $stmt->bind( 16, $billingAddress->getEmail() ); |
||
467 | $stmt->bind( 17, $billingAddress->getTelefax() ); |
||
468 | $stmt->bind( 18, $billingAddress->getWebsite() ); |
||
469 | $stmt->bind( 19, $billingAddress->getLongitude(), \Aimeos\MW\DB\Statement\Base::PARAM_FLOAT ); |
||
470 | $stmt->bind( 20, $billingAddress->getLatitude(), \Aimeos\MW\DB\Statement\Base::PARAM_FLOAT ); |
||
471 | $stmt->bind( 21, $this->plugins['customer.birthday']->translate( $item->getBirthday() ), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
||
1 ignored issue
–
show
|
|||
472 | $stmt->bind( 22, $this->plugins['customer.status']->translate( $item->getStatus() ), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
||
1 ignored issue
–
show
|
|||
473 | $stmt->bind( 23, $item->getPassword() ); |
||
1 ignored issue
–
show
|
|||
474 | $stmt->bind( 24, time(), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); // Modification time |
||
475 | $stmt->bind( 25, $billingAddress->getCountryId() ); |
||
476 | $stmt->bind( 26, implode( ',', $item->getGroups() ) ); |
||
1 ignored issue
–
show
|
|||
477 | $stmt->bind( 27, $item->getPageId(), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); // TYPO3 PID value |
||
1 ignored issue
–
show
|
|||
478 | |||
479 | if( $id !== null ) { |
||
480 | $stmt->bind( 28, $id, \Aimeos\MW\DB\Statement\Base::PARAM_INT ); |
||
481 | $item->setId( $id ); |
||
482 | } else { |
||
483 | $stmt->bind( 28, time(), \Aimeos\MW\DB\Statement\Base::PARAM_INT ); // Creation time |
||
484 | } |
||
485 | |||
486 | $stmt->execute()->finish(); |
||
487 | |||
488 | if( $id === null && $fetch === true ) |
||
489 | { |
||
490 | /** mshop/customer/manager/typo3/newid |
||
491 | * Retrieves the ID generated by the database when inserting a new record |
||
492 | * |
||
493 | * As soon as a new record is inserted into the database table, |
||
494 | * the database server generates a new and unique identifier for |
||
495 | * that record. This ID can be used for retrieving, updating and |
||
496 | * deleting that specific record from the table again. |
||
497 | * |
||
498 | * For MySQL: |
||
499 | * SELECT LAST_INSERT_ID() |
||
500 | * For PostgreSQL: |
||
501 | * SELECT currval('seq_mcus_id') |
||
502 | * For SQL Server: |
||
503 | * SELECT SCOPE_IDENTITY() |
||
504 | * For Oracle: |
||
505 | * SELECT "seq_mcus_id".CURRVAL FROM DUAL |
||
506 | * |
||
507 | * There's no way to retrive the new ID by a SQL statements that |
||
508 | * fits for most database servers as they implement their own |
||
509 | * specific way. |
||
510 | * |
||
511 | * @param string SQL statement for retrieving the last inserted record ID |
||
512 | * @since 2014.03 |
||
513 | * @category Developer |
||
514 | * @see mshop/customer/manager/typo3/insert |
||
515 | * @see mshop/customer/manager/typo3/update |
||
516 | * @see mshop/customer/manager/typo3/delete |
||
517 | * @see mshop/customer/manager/typo3/search |
||
518 | * @see mshop/customer/manager/typo3/count |
||
519 | */ |
||
520 | $path = 'mshop/customer/manager/typo3/newid'; |
||
521 | $item->setId( $this->newId( $conn, $path ) ); |
||
522 | } |
||
523 | |||
524 | $dbm->release( $conn, $dbname ); |
||
525 | } |
||
526 | catch( \Exception $e ) |
||
527 | { |
||
528 | $dbm->release( $conn, $dbname ); |
||
529 | throw $e; |
||
530 | } |
||
531 | |||
532 | $item = $this->savePropertyItems( $item, 'customer' ); |
||
533 | $item = $this->saveAddressItems( $item, 'customer' ); |
||
534 | return $this->saveListItems( $item, 'customer' ); |
||
535 | } |
||
678 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths