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 Export extends AbstractModel implements ExportInterface |
||
19 | { |
||
20 | /** |
||
21 | * @var ProductFactory |
||
22 | */ |
||
23 | private $_productFactory; |
||
24 | |||
25 | /** |
||
26 | * @var \Richdynamix\PersonalisedProducts\Model\ExportFactory |
||
27 | */ |
||
28 | private $_exportFactory; |
||
29 | |||
30 | /** |
||
31 | * @var PersonalisedProductsLogger |
||
32 | */ |
||
33 | protected $_logger; |
||
34 | |||
35 | /** |
||
36 | * Export constructor. |
||
37 | * @param ProductFactory $productFactory |
||
38 | * @param \Magento\Framework\Model\Context $context |
||
39 | * @param \Magento\Framework\Registry $registry |
||
40 | * @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource |
||
41 | * @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection |
||
42 | * @param array $data |
||
43 | */ |
||
44 | public function __construct( |
||
66 | |||
67 | /** |
||
68 | * Export constructor |
||
69 | */ |
||
70 | protected function _construct() |
||
74 | |||
75 | /** |
||
76 | * Get table increment ID |
||
77 | * |
||
78 | * @return mixed |
||
79 | */ |
||
80 | public function getId() |
||
84 | |||
85 | /** |
||
86 | * Get product ID |
||
87 | * |
||
88 | * @return mixed |
||
89 | */ |
||
90 | public function getProductId() |
||
94 | |||
95 | /** |
||
96 | * Get created time |
||
97 | * |
||
98 | * @return mixed |
||
99 | */ |
||
100 | public function getCreationTime() |
||
104 | |||
105 | /** |
||
106 | * Get updated time |
||
107 | * |
||
108 | * @return mixed |
||
109 | */ |
||
110 | public function getUpdateTime() |
||
114 | |||
115 | /** |
||
116 | * Check product is exported |
||
117 | * |
||
118 | * @return bool |
||
119 | */ |
||
120 | public function isExported() |
||
124 | |||
125 | /** |
||
126 | * Set table row increment ID |
||
127 | * |
||
128 | * @param mixed $id |
||
|
|||
129 | * @return $this |
||
130 | */ |
||
131 | public function setId($incrementId) |
||
135 | |||
136 | /** |
||
137 | * Set row product ID |
||
138 | * |
||
139 | * @param $productId |
||
140 | * @return $this |
||
141 | */ |
||
142 | public function setProductId($productId) |
||
146 | |||
147 | /** |
||
148 | * Set row created time |
||
149 | * |
||
150 | * @param $creationTime |
||
151 | * @return $this |
||
152 | */ |
||
153 | public function setCreationTime($creationTime) |
||
157 | |||
158 | /** |
||
159 | * Set row updated time |
||
160 | * |
||
161 | * @param $updatedTime |
||
162 | * @return $this |
||
163 | */ |
||
164 | public function setUpdateTime($updatedTime) |
||
168 | |||
169 | /** |
||
170 | * Set product as being exported |
||
171 | * |
||
172 | * @param $isExported |
||
173 | * @return $this |
||
174 | */ |
||
175 | public function setIsExported($isExported) |
||
179 | |||
180 | /** |
||
181 | * Get category ID's of the product |
||
182 | * |
||
183 | * @return array |
||
184 | */ |
||
185 | public function getCategoryIds() |
||
192 | |||
193 | /** |
||
194 | * Save the new export item with Product Id |
||
195 | * |
||
196 | * @param $productId |
||
197 | * @return Export |
||
198 | */ |
||
199 | View Code Duplication | public function saveProductForExport($productId) |
|
211 | } |
||
212 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.