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 |
||
18 | class Crosssell |
||
19 | { |
||
20 | /** |
||
21 | * @var Complementary |
||
22 | */ |
||
23 | private $_complementaryEngine; |
||
24 | |||
25 | /** |
||
26 | * @var CustomerSession |
||
27 | */ |
||
28 | private $_customerSession; |
||
29 | |||
30 | /** |
||
31 | * @var array |
||
32 | */ |
||
33 | private $_basketProducts; |
||
34 | |||
35 | /** |
||
36 | * @var ProductFactory |
||
37 | */ |
||
38 | private $_productFactory; |
||
39 | |||
40 | /** |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $_products; |
||
44 | |||
45 | /** |
||
46 | * @var Session |
||
47 | */ |
||
48 | protected $_checkoutSession; |
||
49 | |||
50 | /** |
||
51 | * Crosssell constructor. |
||
52 | * @param Complementary $complementaryEngine |
||
53 | * @param CustomerSession $customerSession |
||
54 | * @param ProductFactory $productFactory |
||
55 | * @param Visibility $visibility |
||
56 | * @param Session $session |
||
57 | */ |
||
58 | public function __construct( |
||
70 | |||
71 | /** |
||
72 | * Query the PredictionIO engine for product data |
||
73 | * |
||
74 | * @return array|bool |
||
75 | */ |
||
76 | public function getProductCollection() |
||
87 | |||
88 | /** |
||
89 | * Loop over each of the rules in the returned data from PredictionIO |
||
90 | * |
||
91 | * @param array $items |
||
92 | * @return array |
||
93 | */ |
||
94 | private function _getPredictedProducts(array $items) |
||
103 | |||
104 | /** |
||
105 | * Build product ID collection array from PredictionIO engine data |
||
106 | * |
||
107 | * @param array $items |
||
108 | * @param $productIds |
||
109 | * @return $this |
||
110 | */ |
||
111 | private function _getProductIds(array $items, &$productIds) |
||
121 | |||
122 | /** |
||
123 | * Get a new product collection from prediction IO result set |
||
124 | * |
||
125 | * @param array $personalisedIds |
||
126 | * @return $this |
||
127 | */ |
||
128 | View Code Duplication | public function getPersonalisedProductCollection(array $personalisedIds) |
|
136 | |||
137 | /** |
||
138 | * Get all product ids in the cart |
||
139 | * |
||
140 | * @return array |
||
141 | */ |
||
142 | private function _getCartProductIds() |
||
155 | |||
156 | /** |
||
157 | * Get the quote from the session |
||
158 | * |
||
159 | * @return \Magento\Quote\Model\Quote |
||
160 | */ |
||
161 | public function getQuote() |
||
165 | } |
||
166 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.