Complex classes like Base often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Base, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
21 | abstract class Base extends \Aimeos\Controller\Frontend\Base |
||
22 | { |
||
23 | private $listTypeAttributes = array(); |
||
24 | |||
25 | |||
26 | /** |
||
27 | * Calculates and returns the current price for the given order product and product prices. |
||
28 | * |
||
29 | * @param \Aimeos\MShop\Order\Item\Base\Product\Iface $product Ordered product item |
||
30 | * @param \Aimeos\MShop\Price\Item\Iface[] $prices List of price items |
||
31 | * @param integer $quantity New product quantity |
||
32 | * @return \Aimeos\MShop\Price\Item\Iface Price item with calculated price |
||
33 | */ |
||
34 | protected function calcPrice( \Aimeos\MShop\Order\Item\Base\Product\Iface $product, array $prices, $quantity ) |
||
63 | |||
64 | |||
65 | /** |
||
66 | * Checks if the IDs of the given items are really associated to the product. |
||
67 | * |
||
68 | * @param string $prodId Unique ID of the product |
||
69 | * @param string $domain Domain the references must be of |
||
70 | * @param integer $listTypeId ID of the list type the referenced items must be |
||
71 | * @param array $refIds List of IDs that must be associated to the product |
||
72 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If one or more of the IDs are not associated |
||
73 | */ |
||
74 | protected function checkReferences( $prodId, $domain, $listTypeId, array $refIds ) |
||
104 | |||
105 | |||
106 | /** |
||
107 | * Creates the order product attribute items from the given attribute IDs and updates the price item if necessary. |
||
108 | * |
||
109 | * @param \Aimeos\MShop\Price\Item\Iface $price Price item of the ordered product |
||
110 | * @param string $prodid Unique product ID where the given attributes must be attached to |
||
111 | * @param integer $quantity Number of products that should be added to the basket |
||
112 | * @param array $attributeIds List of attributes IDs of the given type |
||
113 | * @param string $type Attribute type |
||
114 | * @param array $attributeValues Associative list of attribute IDs as keys and their codes as values |
||
115 | * @return array List of items implementing \Aimeos\MShop\Order\Item\Product\Attribute\Iface |
||
116 | */ |
||
117 | protected function createOrderProductAttributes( \Aimeos\MShop\Price\Item\Iface $price, $prodid, $quantity, |
||
154 | |||
155 | |||
156 | /** |
||
157 | * Returns the attribute items for the given attribute IDs. |
||
158 | * |
||
159 | * @param array $attributeIds List of attribute IDs |
||
160 | * @param string[] $domains Names of the domain items that should be fetched too |
||
161 | * @return array List of items implementing \Aimeos\MShop\Attribute\Item\Iface |
||
162 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If the actual attribute number doesn't match the expected one |
||
163 | */ |
||
164 | protected function getAttributes( array $attributeIds, array $domains = array( 'price', 'text' ) ) |
||
193 | |||
194 | |||
195 | /** |
||
196 | * Returns the attribute items using the given order attribute items. |
||
197 | * |
||
198 | * @param \Aimeos\MShop\Order\Item\Base\Product\Attribute\Item[] $orderAttributes List of order product attribute items |
||
199 | * @return \Aimeos\MShop\Attribute\Item\Iface[] Associative list of attribute IDs as key and attribute items as values |
||
200 | */ |
||
201 | protected function getAttributeItems( array $orderAttributes ) |
||
227 | |||
228 | |||
229 | /** |
||
230 | * Retrieves the domain item specified by the given key and value. |
||
231 | * |
||
232 | * @param string $domain Product manager search key |
||
233 | * @param string $key Domain manager search key |
||
234 | * @param string $value Unique domain identifier |
||
235 | * @param string[] $ref List of referenced items that should be fetched too |
||
236 | * @return \Aimeos\MShop\Common\Item\Iface Domain item object |
||
237 | * @throws \Aimeos\Controller\Frontend\Basket\Exception |
||
238 | */ |
||
239 | protected function getDomainItem( $domain, $key, $value, array $ref ) |
||
260 | |||
261 | |||
262 | /** |
||
263 | * Returns the list type item for the given domain and code. |
||
264 | * |
||
265 | * @param string $domain Domain name of the list type |
||
266 | * @param string $code Code of the list type |
||
267 | * @return \Aimeos\MShop\Common\Item\Type\Iface List type item |
||
268 | */ |
||
269 | protected function getProductListTypeItem( $domain, $code ) |
||
296 | |||
297 | |||
298 | /** |
||
299 | * Returns the product variants of a selection product that match the given attributes. |
||
300 | * |
||
301 | * @param \Aimeos\MShop\Product\Item\Iface $productItem Product item including sub-products |
||
302 | * @param array $variantAttributeIds IDs for the variant-building attributes |
||
303 | * @param array $domains Names of the domain items that should be fetched too |
||
304 | * @return array List of products matching the given attributes |
||
305 | */ |
||
306 | protected function getProductVariants( \Aimeos\MShop\Product\Item\Iface $productItem, array $variantAttributeIds, |
||
344 | |||
345 | |||
346 | /** |
||
347 | * Returns the value of an array or the default value if it's not available. |
||
348 | * |
||
349 | * @param array $values Associative list of key/value pairs |
||
350 | * @param string $name Name of the key to return the value for |
||
351 | * @param mixed $default Default value if no value is available for the given name |
||
352 | * @return mixed Value from the array or default value |
||
353 | */ |
||
354 | protected function getValue( array $values, $name, $default = null ) |
||
362 | |||
363 | |||
364 | /** |
||
365 | * Checks if the product is part of at least one category in the product catalog. |
||
366 | * |
||
367 | * @param string $prodid Unique ID of the product |
||
368 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If product is not associated to at least one category |
||
369 | * @deprecated 2016.05 |
||
370 | */ |
||
371 | protected function checkCategory( $prodid ) |
||
391 | |||
392 | |||
393 | /** |
||
394 | * Edits the changed product to the basket if it's in stock. |
||
395 | * |
||
396 | * @param \Aimeos\MShop\Order\Item\Base\Product\Iface $orderBaseProductItem Old order product from basket |
||
397 | * @param string $productId Unique ID of the product item that belongs to the order product |
||
398 | * @param integer $quantity Number of products to add to the basket |
||
399 | * @param array $options Associative list of options |
||
400 | * @param string $warehouse Warehouse code for retrieving the stock level |
||
401 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If there's not enough stock available |
||
402 | * @deprecated 2016.05 |
||
403 | */ |
||
404 | protected function addProductInStock( \Aimeos\MShop\Order\Item\Base\Product\Iface $orderBaseProductItem, |
||
432 | |||
433 | |||
434 | /** |
||
435 | * Edits the changed product to the basket if it's in stock. |
||
436 | * |
||
437 | * @param \Aimeos\MShop\Order\Item\Base\Product\Iface $product Old order product from basket |
||
438 | * @param \Aimeos\MShop\Product\Item\Iface $productItem Product item that belongs to the order product |
||
439 | * @param integer $quantity New product quantity |
||
440 | * @param integer $position Position of the old order product in the basket |
||
441 | * @param array Associative list of options |
||
442 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If there's not enough stock available |
||
443 | * @deprecated 2016.05 |
||
444 | */ |
||
445 | protected function editProductInStock( \Aimeos\MShop\Order\Item\Base\Product\Iface $product, |
||
467 | |||
468 | |||
469 | /** |
||
470 | * Returns the highest stock level for the product. |
||
471 | * |
||
472 | * @param string $prodid Unique ID of the product |
||
473 | * @param string $warehouse Unique code of the warehouse |
||
474 | * @return integer|null Number of available items in stock (null for unlimited stock) |
||
475 | * @deprecated 2016.04 Use basket stock decorator instead |
||
476 | */ |
||
477 | protected function getStockLevel( $prodid, $warehouse ) |
||
510 | } |
||
511 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.