Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
16 | class EbayEnterprise_Tax_Model_Observer |
||
17 | { |
||
18 | /** @var bool Lock to guard against too much recursion in quote collect totals */ |
||
19 | protected static $lockRecollectTotals = false; |
||
20 | /** @var EbayEnterprise_Tax_Model_Collector */ |
||
21 | protected $taxCollector; |
||
22 | /** @var EbayEnterprise_Eb2cCore_Model_Session */ |
||
23 | protected $coreSession; |
||
24 | /** @var EbayEnterprise_MageLog_Helper_Data */ |
||
25 | protected $logger; |
||
26 | /** @var EbayEnterprise_MageLog_Helper_Context */ |
||
27 | protected $logContext; |
||
28 | |||
29 | /** |
||
30 | * @param array |
||
31 | */ |
||
32 | View Code Duplication | public function __construct(array $args = []) |
|
46 | |||
47 | /** |
||
48 | * Enforce type checks on construct args array. |
||
49 | * |
||
50 | * @param EbayEnterprise_Tax_Model_Collector |
||
51 | * @param EbayEnterprise_Tax_Model_Session |
||
52 | * @param EbayEnterprise_MageLog_Helper_Data |
||
53 | * @param EbayEnterprise_MageLog_Helper_Context |
||
54 | * @return array |
||
55 | */ |
||
56 | protected function checkTypes( |
||
64 | |||
65 | /** |
||
66 | * Fill in default values. |
||
67 | * |
||
68 | * @param string |
||
69 | * @param array |
||
70 | * @param mixed |
||
71 | * @return mixed |
||
72 | */ |
||
73 | protected function nullCoalesce(array $arr, $key, $default) |
||
77 | |||
78 | /** |
||
79 | * Get the session instance containing collected tax data for the quote. |
||
80 | * Populates the class property if not set when requested. The property |
||
81 | * will not be set during construction to minimize the risk of initializing |
||
82 | * the session instance before the user session has been started. |
||
83 | * |
||
84 | * @return EbayEnterprise_Eb2cCore_Model_Session |
||
85 | */ |
||
86 | protected function getCoreSession() |
||
93 | |||
94 | /** |
||
95 | * Collect new tax totals if necessary after collecting quote totals. |
||
96 | * Tax totals collected after all other quote totals so tax totals for the |
||
97 | * entire quote may be collected at one - all other totals for all other |
||
98 | * addresses must have already been collected. |
||
99 | * |
||
100 | * If new taxes are collected, all quote totals must be recollected. |
||
101 | * |
||
102 | * @param Varien_Event_Observer |
||
103 | * @return self |
||
104 | */ |
||
105 | public function handleSalesQuoteCollectTotalsAfter(Varien_Event_Observer $observer) |
||
145 | |||
146 | /** |
||
147 | * set the tax header error flag on the order create request. |
||
148 | * @param Varien_Event_Observer |
||
149 | * @return self |
||
150 | */ |
||
151 | public function handleOrderCreateBeforeAttachEvent(Varien_Event_Observer $observer) |
||
160 | |||
161 | /** |
||
162 | * set gifting tax data on the shipgroup payload for the order create request |
||
163 | * @param Varien_Event_Observer |
||
164 | * @return self |
||
165 | */ |
||
166 | public function handleOrderCreateShipGroupEvent(Varien_Event_Observer $observer) |
||
178 | |||
179 | /** |
||
180 | * set tax data on the orderitem payload for the order create request |
||
181 | * @param Varien_Event_Observer |
||
182 | * @return self |
||
183 | */ |
||
184 | public function handleOrderCreateItemEvent(Varien_Event_Observer $observer) |
||
201 | |||
202 | /** |
||
203 | * Recollect quote totals to update amounts based on newly received tax |
||
204 | * data. This collect totals call is expected to happen recursively within |
||
205 | * collect totals. The flags in eb2ccore/session are expected to prevent |
||
206 | * going beyond a single recursive call to collect totals. As an additional |
||
207 | * precaution, a lock is also used to prevent unexpected recursion. |
||
208 | * |
||
209 | * @param Mage_Sales_Model_Quote |
||
210 | * @return Mage_Sales_Model_Quote |
||
211 | */ |
||
212 | protected function recollectTotals(Mage_Sales_Model_Quote $quote) |
||
232 | } |
||
233 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.