Complex classes like Standard 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 Standard, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
21 | class Standard |
||
22 | extends Base |
||
2 ignored issues
–
show
|
|||
23 | implements Iface, \Aimeos\Controller\Frontend\Common\Iface |
||
1 ignored issue
–
show
|
|||
24 | { |
||
25 | private $basket; |
||
26 | private $domainManager; |
||
27 | |||
28 | |||
29 | /** |
||
30 | * Initializes the frontend controller. |
||
31 | * |
||
32 | * @param \Aimeos\MShop\Context\Item\Iface $context Object storing the required instances for manaing databases |
||
33 | * connections, logger, session, etc. |
||
34 | */ |
||
35 | public function __construct( \Aimeos\MShop\Context\Item\Iface $context ) |
||
44 | |||
45 | |||
46 | /** |
||
47 | * Empties the basket and removing all products, addresses, services, etc. |
||
48 | */ |
||
49 | public function clear() |
||
54 | |||
55 | |||
56 | /** |
||
57 | * Returns the basket object. |
||
58 | * |
||
59 | * @return \Aimeos\MShop\Order\Item\Base\Iface Basket holding products, addresses and delivery/payment options |
||
60 | */ |
||
61 | public function get() |
||
65 | |||
66 | |||
67 | /** |
||
68 | * Explicitely persists the basket content |
||
69 | */ |
||
70 | public function save() |
||
76 | |||
77 | |||
78 | /** |
||
79 | * Adds a categorized product to the basket of the user stored in the session. |
||
80 | * |
||
81 | * @param string $prodid ID of the base product to add |
||
82 | * @param integer $quantity Amount of products that should by added |
||
83 | * @param array $options Possible options are: 'stock'=>true|false and 'variant'=>true|false |
||
84 | * The 'stock'=>false option allows adding products without being in stock. |
||
85 | * The 'variant'=>false option allows adding the selection product to the basket |
||
86 | * instead of the specific sub-product if the variant-building attribute IDs |
||
87 | * doesn't match a specific sub-product or if the attribute IDs are missing. |
||
88 | * @param array $variantAttributeIds List of variant-building attribute IDs that identify a specific product |
||
89 | * in a selection products |
||
90 | * @param array $configAttributeIds List of attribute IDs that doesn't identify a specific product in a |
||
91 | * selection of products but are stored together with the product (e.g. for configurable products) |
||
92 | * @param array $hiddenAttributeIds List of attribute IDs that should be stored along with the product in the order |
||
93 | * @param array $customAttributeValues Associative list of attribute IDs and arbitrary values that should be stored |
||
94 | * along with the product in the order |
||
95 | * @param string $stocktype Unique code of the stock type to deliver the products from |
||
96 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If the product isn't available |
||
97 | */ |
||
98 | public function addProduct( $prodid, $quantity = 1, array $options = array(), array $variantAttributeIds = array(), |
||
141 | |||
142 | |||
143 | /** |
||
144 | * Deletes a product item from the basket. |
||
145 | * |
||
146 | * @param integer $position Position number (key) of the order product item |
||
147 | */ |
||
148 | public function deleteProduct( $position ) |
||
161 | |||
162 | |||
163 | /** |
||
164 | * Edits the quantity of a product item in the basket. |
||
165 | * |
||
166 | * @param integer $position Position number (key) of the order product item |
||
167 | * @param integer $quantity New quantiy of the product item |
||
168 | * @param array $options Possible options are: 'stock'=>true|false |
||
169 | * The 'stock'=>false option allows adding products without being in stock. |
||
170 | * @param string[] $configAttributeCodes Codes of the product config attributes that should be REMOVED |
||
171 | */ |
||
172 | public function editProduct( $position, $quantity, array $options = array(), |
||
203 | |||
204 | |||
205 | /** |
||
206 | * Adds the given coupon code and updates the basket. |
||
207 | * |
||
208 | * @param string $code Coupon code entered by the user |
||
209 | * @throws \Aimeos\Controller\Frontend\Basket\Exception if the coupon code is invalid or not allowed |
||
210 | */ |
||
211 | public function addCoupon( $code ) |
||
256 | |||
257 | |||
258 | /** |
||
259 | * Removes the given coupon code and its effects from the basket. |
||
260 | * |
||
261 | * @param string $code Coupon code entered by the user |
||
262 | * @throws \Aimeos\Controller\Frontend\Basket\Exception if the coupon code is invalid |
||
263 | */ |
||
264 | public function deleteCoupon( $code ) |
||
281 | |||
282 | |||
283 | /** |
||
284 | * Sets the address of the customer in the basket. |
||
285 | * |
||
286 | * @param string $type Address type constant from \Aimeos\MShop\Order\Item\Base\Address\Base |
||
287 | * @param \Aimeos\MShop\Common\Item\Address\Iface|array|null $value Address object or array with key/value pairs of address or null to remove address from basket |
||
288 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If the billing or delivery address is not of any required type of |
||
289 | * if one of the keys is invalid when using an array with key/value pairs |
||
290 | */ |
||
291 | public function setAddress( $type, $value ) |
||
317 | |||
318 | |||
319 | /** |
||
320 | * Sets the delivery/payment service item based on the service ID. |
||
321 | * |
||
322 | * @param string $type Service type code like 'payment' or 'delivery' |
||
323 | * @param string $id Unique ID of the service item |
||
324 | * @param array $attributes Associative list of key/value pairs containing the attributes selected or |
||
325 | * entered by the customer when choosing one of the delivery or payment options |
||
326 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If there is no price to the service item attached |
||
327 | */ |
||
328 | public function setService( $type, $id, array $attributes = array() ) |
||
366 | |||
367 | |||
368 | /** |
||
369 | * Adds the bundled products to the order product item. |
||
370 | * |
||
371 | * @param \Aimeos\MShop\Order\Item\Base\Product\Iface $orderBaseProductItem Order product item |
||
372 | * @param \Aimeos\MShop\Product\Item\Iface $productItem Bundle product item |
||
373 | * @param array $variantAttributeIds List of product variant attribute IDs |
||
374 | * @param string $stocktype |
||
375 | */ |
||
376 | protected function addBundleProducts( \Aimeos\MShop\Order\Item\Base\Product\Iface $orderBaseProductItem, |
||
415 | |||
416 | |||
417 | /** |
||
418 | * Creates the order product attribute items from the given attribute IDs and updates the price item if necessary. |
||
419 | * |
||
420 | * @param \Aimeos\MShop\Price\Item\Iface $price Price item of the ordered product |
||
421 | * @param string $prodid Unique product ID where the given attributes must be attached to |
||
422 | * @param integer $quantity Number of products that should be added to the basket |
||
423 | * @param array $attributeIds List of attributes IDs of the given type |
||
424 | * @param string $type Attribute type |
||
425 | * @param array $attributeValues Associative list of attribute IDs as keys and their codes as values |
||
426 | * @return array List of items implementing \Aimeos\MShop\Order\Item\Product\Attribute\Iface |
||
427 | */ |
||
428 | protected function createOrderProductAttributes( \Aimeos\MShop\Price\Item\Iface $price, $prodid, $quantity, |
||
465 | |||
466 | |||
467 | /** |
||
468 | * Retrieves the domain item specified by the given key and value. |
||
469 | * |
||
470 | * @param string $domain Product manager search key |
||
471 | * @param string $key Domain manager search key |
||
472 | * @param string $value Unique domain identifier |
||
473 | * @param string[] $ref List of referenced items that should be fetched too |
||
474 | * @return \Aimeos\MShop\Common\Item\Iface Domain item object |
||
475 | * @throws \Aimeos\Controller\Frontend\Basket\Exception |
||
476 | */ |
||
477 | protected function getDomainItem( $domain, $key, $value, array $ref ) |
||
498 | |||
499 | |||
500 | /** |
||
501 | * Returns the variant attributes and updates the price list if necessary. |
||
502 | * |
||
503 | * @param \Aimeos\MShop\Order\Item\Base\Product\Iface $orderBaseProductItem Order product item |
||
504 | * @param \Aimeos\MShop\Product\Item\Iface &$productItem Product item which is replaced if necessary |
||
505 | * @param array &$prices List of product prices that will be updated if necessary |
||
506 | * @param array $variantAttributeIds List of product variant attribute IDs |
||
507 | * @param array $options Associative list of options |
||
508 | * @return \Aimeos\MShop\Order\Item\Base\Product\Attribute\Iface[] List of order product attributes |
||
509 | * @throws \Aimeos\Controller\Frontend\Basket\Exception If no product variant is found |
||
510 | */ |
||
511 | protected function getVariantDetails( \Aimeos\MShop\Order\Item\Base\Product\Iface $orderBaseProductItem, |
||
559 | |||
560 | |||
561 | /** |
||
562 | * Fills the order address object with the values from the array. |
||
563 | * |
||
564 | * @param \Aimeos\MShop\Order\Item\Base\Address\Iface $address Address item to store the values into |
||
565 | * @param array $map Associative array of key/value pairs. The keys must be the same as when calling toArray() from |
||
566 | * an address item. |
||
567 | * @throws \Aimeos\Controller\Frontend\Basket\Exception |
||
568 | */ |
||
569 | protected function setAddressFromArray( \Aimeos\MShop\Order\Item\Base\Address\Iface $address, array $map ) |
||
583 | } |
||
584 |