Conditions | 8 |
Paths | 9 |
Total Lines | 65 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 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, float $quantity = 1, |
||
38 | array $variant = [], array $config = [], array $custom = [], string $stocktype = 'default', ?string $siteId = null |
||
39 | ) : \Aimeos\Controller\Frontend\Basket\Iface |
||
40 | { |
||
41 | if( $product->getType() !== 'select' ) |
||
42 | { |
||
43 | $this->getController()->addProduct( $product, $quantity, $variant, $config, $custom, $stocktype, $siteId ); |
||
44 | return $this; |
||
45 | } |
||
46 | |||
47 | $attr = []; |
||
48 | $prices = $product->getRefItems( 'price', 'default', 'default' ); |
||
49 | $hidden = $product->getRefItems( 'attribute', null, 'hidden' ); |
||
50 | |||
51 | $productItem = $this->getArticle( $product, $variant ); |
||
52 | $quantity = $this->call( 'checkQuantity', $productItem, $quantity ); |
||
53 | |||
54 | $orderProductItem = \Aimeos\MShop::create( $this->context(), 'order' ) |
||
55 | ->createProduct() |
||
|
|||
56 | ->copyFrom( $product ) |
||
57 | ->setQuantity( $quantity ) |
||
58 | ->setStockType( $stocktype ) |
||
59 | ->setName( $productItem->getName() ) |
||
60 | ->setScale( $productItem->getScale() ) |
||
61 | ->setProductId( $productItem->getId() ) |
||
62 | ->setParentProductId( $product->getId() ) |
||
63 | ->setProductCode( $productItem->getCode() ) |
||
64 | ->setSiteId( $siteId ?: $productItem->getSiteId() ); |
||
65 | |||
66 | $this->call( 'checkAttributes', [$product, $productItem], 'custom', array_keys( $custom ) ); |
||
67 | $this->call( 'checkAttributes', [$product, $productItem], 'config', array_keys( $config ) ); |
||
68 | |||
69 | if( !( $subprices = $productItem->getRefItems( 'price', 'default', 'default' ) )->isEmpty() ) { |
||
70 | $prices = $subprices; |
||
71 | } |
||
72 | |||
73 | if( $mediaItem = $productItem->getRefItems( 'media', 'default', 'default' )->first() ) { |
||
74 | $orderProductItem->setMediaUrl( $mediaItem->getPreview() ); |
||
75 | } |
||
76 | |||
77 | $hidden->union( $productItem->getRefItems( 'attribute', null, 'hidden' ) ); |
||
78 | |||
79 | $orderManager = \Aimeos\MShop::create( $this->context(), 'order' ); |
||
80 | $attributes = $productItem->getRefItems( 'attribute', null, 'variant' ); |
||
81 | |||
82 | foreach( $this->call( 'getAttributes', $attributes->keys()->toArray(), ['text'] ) as $attrItem ) { |
||
83 | $attr[] = $orderManager->createProductAttribute()->copyFrom( $attrItem )->setType( 'variant' ); |
||
84 | } |
||
85 | |||
86 | $custAttr = $this->call( 'getOrderProductAttributes', 'custom', array_keys( $custom ), $custom ); |
||
87 | $confAttr = $this->call( 'getOrderProductAttributes', 'config', array_keys( $config ), [], $config ); |
||
88 | $hideAttr = $this->call( 'getOrderProductAttributes', 'hidden', $hidden->keys()->toArray() ); |
||
89 | |||
90 | $orderProductItem->setAttributeItems( array_merge( $attr, $custAttr, $confAttr, $hideAttr ) ); |
||
91 | |||
92 | $price = $this->call( 'calcPrice', $orderProductItem, $prices, $quantity ); |
||
93 | $orderProductItem |
||
94 | ->setPrice( $price ) |
||
95 | ->setSiteId( $siteId ?: $price->getSiteId() ) |
||
96 | ->setVendor( $this->getVendor( $siteId ?: $price->getSiteId() ) ); |
||
97 | |||
98 | $this->getController()->get()->addProduct( $orderProductItem ); |
||
99 | $this->getController()->save(); |
||
100 | |||
101 | return $this; |
||
102 | } |
||
213 |
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.