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 implements Iface |
||
22 | { |
||
23 | private $listTypeItems = []; |
||
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 ) |
||
77 | |||
78 | |||
79 | /** |
||
80 | * Checks if the reference IDs are really associated to the product |
||
81 | * |
||
82 | * @param string|array $prodId Unique ID of the product or list of product IDs |
||
83 | * @param string $domain Domain the references must be of |
||
84 | * @param array $refMap Associative list of list type codes as keys and lists of reference IDs as values |
||
85 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If one or more of the IDs are not associated |
||
86 | */ |
||
87 | protected function checkListRef( $prodId, $domain, array $refMap ) |
||
125 | |||
126 | |||
127 | /** |
||
128 | * Checks if the IDs of the given items are really associated to the product. |
||
129 | * |
||
130 | * @param string|array $prodId Unique ID of the product or list of product IDs |
||
131 | * @param string $domain Domain the references must be of |
||
132 | * @param integer $listTypeId ID of the list type the referenced items must be |
||
133 | * @param array $refIds List of IDs that must be associated to the product |
||
134 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If one or more of the IDs are not associated |
||
135 | * @deprecated Use checkListRef() instead |
||
136 | */ |
||
137 | protected function checkReferences( $prodId, $domain, $listTypeId, array $refIds ) |
||
167 | |||
168 | |||
169 | /** |
||
170 | * Checks for a locale mismatch and migrates the products to the new basket if necessary. |
||
171 | * |
||
172 | * @param string $type Basket type |
||
173 | */ |
||
174 | protected function checkLocale( $type ) |
||
210 | |||
211 | |||
212 | /** |
||
213 | * Migrates the addresses from the old basket to the current one. |
||
214 | * |
||
215 | * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object |
||
216 | * @param array $errors Associative list of previous errors |
||
217 | * @param string $localeKey Unique identifier of the site, language and currency |
||
218 | * @return array Associative list of errors occured |
||
219 | */ |
||
220 | protected function copyAddresses( \Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey ) |
||
240 | |||
241 | |||
242 | /** |
||
243 | * Migrates the coupons from the old basket to the current one. |
||
244 | * |
||
245 | * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object |
||
246 | * @param array $errors Associative list of previous errors |
||
247 | * @param string $localeKey Unique identifier of the site, language and currency |
||
248 | * @return array Associative list of errors occured |
||
249 | */ |
||
250 | protected function copyCoupons( \Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey ) |
||
270 | |||
271 | |||
272 | /** |
||
273 | * Migrates the products from the old basket to the current one. |
||
274 | * |
||
275 | * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object |
||
276 | * @param array $errors Associative list of previous errors |
||
277 | * @param string $localeKey Unique identifier of the site, language and currency |
||
278 | * @return array Associative list of errors occured |
||
279 | */ |
||
280 | protected function copyProducts( \Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors, $localeKey ) |
||
322 | |||
323 | |||
324 | /** |
||
325 | * Migrates the services from the old basket to the current one. |
||
326 | * |
||
327 | * @param \Aimeos\MShop\Order\Item\Base\Iface $basket Basket object |
||
328 | * @param array $errors Associative list of previous errors |
||
329 | * @return array Associative list of errors occured |
||
330 | */ |
||
331 | protected function copyServices( \Aimeos\MShop\Order\Item\Base\Iface $basket, array $errors ) |
||
354 | |||
355 | |||
356 | /** |
||
357 | * Creates the order product attribute items from the given attribute IDs and updates the price item if necessary. |
||
358 | * |
||
359 | * @param \Aimeos\MShop\Price\Item\Iface $price Price item of the ordered product |
||
360 | * @param string|array $prodid Unique product ID or list of product IDs where the given attributes must be attached to |
||
361 | * @param integer $quantity Number of products that should be added to the basket |
||
362 | * @param array $attributeIds List of attributes IDs of the given type |
||
363 | * @param string $type Attribute type |
||
364 | * @param array $attributeValues Associative list of attribute IDs as keys and their codes as values |
||
365 | * @return array List of items implementing \Aimeos\MShop\Order\Item\Product\Attribute\Iface |
||
366 | * @deprecated Use getOrderProductAttributes(), checkReferences() and calcPrice() instead |
||
367 | */ |
||
368 | protected function createOrderProductAttributes( \Aimeos\MShop\Price\Item\Iface $price, $prodid, $quantity, |
||
405 | |||
406 | |||
407 | /** |
||
408 | * Returns the attribute items for the given attribute IDs. |
||
409 | * |
||
410 | * @param array $attributeIds List of attribute IDs |
||
411 | * @param string[] $domains Names of the domain items that should be fetched too |
||
412 | * @return array List of items implementing \Aimeos\MShop\Attribute\Item\Iface |
||
413 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If the actual attribute number doesn't match the expected one |
||
414 | */ |
||
415 | protected function getAttributes( array $attributeIds, array $domains = array( 'price', 'text' ) ) |
||
444 | |||
445 | |||
446 | /** |
||
447 | * Returns the attribute items using the given order attribute items. |
||
448 | * |
||
449 | * @param \Aimeos\MShop\Order\Item\Base\Product\Attribute\Item[] $orderAttributes List of order product attribute items |
||
450 | * @return \Aimeos\MShop\Attribute\Item\Iface[] Associative list of attribute IDs as key and attribute items as values |
||
451 | */ |
||
452 | protected function getAttributeItems( array $orderAttributes ) |
||
478 | |||
479 | |||
480 | /** |
||
481 | * Retrieves the domain item specified by the given key and value. |
||
482 | * |
||
483 | * @param string $domain Product manager search key |
||
484 | * @param string $key Domain manager search key |
||
485 | * @param string $value Unique domain identifier |
||
486 | * @param string[] $ref List of referenced items that should be fetched too |
||
487 | * @return \Aimeos\MShop\Common\Item\Iface Domain item object |
||
488 | * @throws \Aimeos\Controller\Frontend\Basket\Exception |
||
489 | * @deprecated Use getItem() or findItem() instead |
||
490 | */ |
||
491 | protected function getDomainItem( $domain, $key, $value, array $ref ) |
||
512 | |||
513 | |||
514 | /** |
||
515 | * Returns the order product attribute items for the given IDs and values |
||
516 | * |
||
517 | * @param string $type Attribute type code |
||
518 | * @param array $attributeIds List of attributes IDs of the given type |
||
519 | * @param array $attributeValues Associative list of attribute IDs as keys and their codes as values |
||
520 | * @return array List of items implementing \Aimeos\MShop\Order\Item\Product\Attribute\Iface |
||
521 | */ |
||
522 | protected function getOrderProductAttributes( $type, array $attributeIds, array $attributeValues = [] ) |
||
550 | |||
551 | |||
552 | /** |
||
553 | * Returns the list type item for the given domain and code. |
||
554 | * |
||
555 | * @param string $domain Domain name of the list type |
||
556 | * @param string $code Code of the list type |
||
557 | * @return \Aimeos\MShop\Common\Item\Type\Iface List type item |
||
558 | */ |
||
559 | protected function getProductListTypeItem( $domain, $code ) |
||
578 | |||
579 | |||
580 | /** |
||
581 | * Returns the product variants of a selection product that match the given attributes. |
||
582 | * |
||
583 | * @param \Aimeos\MShop\Product\Item\Iface $productItem Product item including sub-products |
||
584 | * @param array $variantAttributeIds IDs for the variant-building attributes |
||
585 | * @param array $domains Names of the domain items that should be fetched too |
||
586 | * @return array List of products matching the given attributes |
||
587 | */ |
||
588 | protected function getProductVariants( \Aimeos\MShop\Product\Item\Iface $productItem, array $variantAttributeIds, |
||
626 | |||
627 | |||
628 | /** |
||
629 | * Returns the value of an array or the default value if it's not available. |
||
630 | * |
||
631 | * @param array $values Associative list of key/value pairs |
||
632 | * @param string $name Name of the key to return the value for |
||
633 | * @param mixed $default Default value if no value is available for the given name |
||
634 | * @return mixed Value from the array or default value |
||
635 | */ |
||
636 | protected function getValue( array $values, $name, $default = null ) |
||
644 | } |
||
645 |
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.