| Conditions | 5 |
| Paths | 9 |
| Total Lines | 53 |
| Code Lines | 32 |
| 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 |
||
| 37 | public function addProduct( \Aimeos\MShop\Product\Item\Iface $product, $quantity = 1, |
||
| 38 | array $variant = [], array $config = [], array $custom = [], $stocktype = 'default', $supplier = null ) |
||
| 39 | { |
||
| 40 | if( $product->getType() !== 'select' ) |
||
| 41 | { |
||
| 42 | $this->getController()->addProduct( $product, $quantity, $variant, $config, $custom, $stocktype, $supplier ); |
||
| 43 | return $this; |
||
| 44 | } |
||
| 45 | |||
| 46 | $attr = []; |
||
| 47 | $prodId = $product->getId(); |
||
| 48 | $prices = $product->getRefItems( 'price', 'default', 'default' ); |
||
| 49 | $hidden = $product->getRefItems( 'attribute', null, 'hidden' ); |
||
| 50 | |||
| 51 | $orderBaseProductItem = \Aimeos\MShop::create( $this->getContext(), 'order/base/product' )->createItem(); |
||
| 52 | $orderBaseProductItem = $orderBaseProductItem->copyFrom( $product ); |
||
|
|
|||
| 53 | |||
| 54 | $product = $this->getArticle( $product, $variant ); |
||
| 55 | $orderBaseProductItem->setProductCode( $product->getCode() ); |
||
| 56 | |||
| 57 | $attributeMap = ['custom' => array_keys( $custom ), 'config' => array_keys( $config )]; |
||
| 58 | $this->checkListRef( [$prodId, $product->getId()], 'attribute', $attributeMap ); |
||
| 59 | |||
| 60 | if( ( $subprices = $product->getRefItems( 'price', 'default', 'default' ) ) !== [] ) { |
||
| 61 | $prices = $subprices; |
||
| 62 | } |
||
| 63 | |||
| 64 | if( ( $mediaItems = $product->getRefItems( 'media', 'default', 'default' ) ) !== [] ) { |
||
| 65 | $orderBaseProductItem->setMediaUrl( current( $mediaItems )->getPreview() ); |
||
| 66 | } |
||
| 67 | |||
| 68 | $hidden += $product->getRefItems( 'attribute', null, 'hidden' ); |
||
| 69 | |||
| 70 | $orderProductAttrManager = \Aimeos\MShop::create( $this->getContext(), 'order/base/product/attribute' ); |
||
| 71 | $attributes = $product->getRefItems( 'attribute', null, 'variant' ); |
||
| 72 | |||
| 73 | foreach( $this->getAttributes( array_keys( $attributes ), ['text'] ) as $attrItem ) { |
||
| 74 | $attr[] = $orderProductAttrManager->createItem()->copyFrom( $attrItem )->setType( 'variant' ); |
||
| 75 | } |
||
| 76 | |||
| 77 | $custAttr = $this->getOrderProductAttributes( 'custom', array_keys( $custom ), $custom ); |
||
| 78 | $confAttr = $this->getOrderProductAttributes( 'config', array_keys( $config ), [], $config ); |
||
| 79 | $hideAttr = $this->getOrderProductAttributes( 'hidden', array_keys( $hidden ) ); |
||
| 80 | |||
| 81 | $orderBaseProductItem = $orderBaseProductItem->setQuantity( $quantity ) |
||
| 82 | ->setAttributeItems( array_merge( $attr, $custAttr, $confAttr, $hideAttr ) ) |
||
| 83 | ->setPrice( $this->calcPrice( $orderBaseProductItem, $prices, $quantity ) ) |
||
| 84 | ->setStockType( $stocktype )->setSupplierCode( $supplier ); |
||
| 85 | |||
| 86 | $this->getController()->get()->addProduct( $orderBaseProductItem ); |
||
| 87 | $this->getController()->save(); |
||
| 88 | |||
| 89 | return $this; |
||
| 90 | } |
||
| 154 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.