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_Helper_Item_Selection |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * Filter out the children of configurable products. |
||
| 20 | * |
||
| 21 | * @param Mage_Sales_Model_Quote_Item_Abstract[] |
||
| 22 | * @return Mage_Sales_Model_Quote_Item_Abstract[] |
||
| 23 | */ |
||
| 24 | public function selectFrom(array $items) |
||
| 25 | { |
||
| 26 | $predicate = function (Mage_Sales_Model_Quote_Item_Abstract $item) { |
||
| 27 | $parentItem = $item->getParentItem(); |
||
| 28 | return !($parentItem && $parentItem->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE); |
||
| 29 | } |
||
| 30 | return array_filter($items, $predicate); |
||
|
|
|||
| 31 | } |
||
| 32 | } |
||
| 33 |