| Conditions | 8 |
| Paths | 12 |
| Total Lines | 51 |
| Code Lines | 15 |
| 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 |
||
| 101 | protected function getArticle( \Aimeos\MShop\Product\Item\Iface $productItem, array $variant ) |
||
| 102 | { |
||
| 103 | $items = []; |
||
| 104 | $context = $this->getContext(); |
||
| 105 | |||
| 106 | /** controller/frontend/basket/require-variant |
||
| 107 | * A variant of a selection product must be chosen |
||
| 108 | * |
||
| 109 | * Selection products normally consist of several article variants and |
||
| 110 | * by default exactly one article variant of a selection product can be |
||
| 111 | * put into the basket. |
||
| 112 | * |
||
| 113 | * By setting this option to false, the selection product including the |
||
| 114 | * chosen attributes (if any attribute values were selected) can be put |
||
| 115 | * into the basket as well. This makes it possible to get all articles |
||
| 116 | * or a subset of articles (e.g. all of a color) at once. |
||
| 117 | * |
||
| 118 | * This option replace the "client/html/basket/require-variant" setting. |
||
| 119 | * |
||
| 120 | * @param boolean True if a variant must be chosen, false if also the selection product with attributes can be added |
||
| 121 | * @since 2018.01 |
||
| 122 | * @category Developer |
||
| 123 | * @category User |
||
| 124 | */ |
||
| 125 | $requireVariant = $context->getConfig()->get( 'controller/frontend/basket/require-variant', true ); |
||
| 126 | |||
| 127 | foreach( $productItem->getRefItems( 'product', 'default', 'default' ) as $item ) |
||
| 128 | { |
||
| 129 | foreach( $variant as $id ) |
||
| 130 | { |
||
| 131 | if( $item->getListItem( 'attribute', 'variant', $id ) === null ) { |
||
| 132 | continue 2; |
||
| 133 | } |
||
| 134 | } |
||
| 135 | |||
| 136 | $items[] = $item; |
||
| 137 | } |
||
| 138 | |||
| 139 | if( count( $items ) > 1 ) |
||
| 140 | { |
||
| 141 | $msg = $context->getI18n()->dt( 'controller/frontend', 'No unique article found for selected attributes and product ID "%1$s"' ); |
||
| 142 | throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( $msg, $productItem->getId() ) ); |
||
| 143 | } |
||
| 144 | |||
| 145 | if( empty( $items ) && $requireVariant != false ) // count == 0 |
||
| 146 | { |
||
| 147 | $msg = $context->getI18n()->dt( 'controller/frontend', 'No article found for selected attributes and product ID "%1$s"' ); |
||
| 148 | throw new \Aimeos\Controller\Frontend\Basket\Exception( sprintf( $msg, $productItem->getId() ) ); |
||
| 149 | } |
||
| 150 | |||
| 151 | return current( $items ) ?: $productItem; |
||
| 152 | } |
||
| 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.