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 |
||
22 | class Adtraction extends AbstractNetwork implements NetworkInterface |
||
23 | { |
||
24 | /** |
||
25 | * @var object |
||
26 | */ |
||
27 | private $_network = null; |
||
28 | private $_apiClient = null; |
||
29 | private $_username = ''; |
||
30 | private $_password = ''; |
||
31 | private $_idSite = ''; |
||
32 | private $_logged = false; |
||
33 | protected $_tracking_parameter = 'epi'; |
||
34 | |||
35 | /** |
||
36 | * Adtraction constructor. |
||
37 | * @param string $username |
||
38 | * @param string $password |
||
39 | * @param string $idSite |
||
40 | */ |
||
41 | View Code Duplication | public function __construct(string $username, string $password, string $idSite = '') |
|
50 | |||
51 | public function login(string $username, string $password, string $idSite = ''): bool |
||
74 | |||
75 | /** |
||
76 | * @return bool |
||
77 | */ |
||
78 | public function checkLogin() : bool |
||
82 | |||
83 | /** |
||
84 | * @return array of Merchants |
||
85 | */ |
||
86 | View Code Duplication | public function getMerchants() : array |
|
111 | |||
112 | /** |
||
113 | * @param int|null $merchantID |
||
114 | * @param int $page |
||
115 | * @param int $items_per_page |
||
116 | * |
||
117 | * @return DealsResultset |
||
118 | */ |
||
119 | public function getDeals($merchantID,int $page=0,int $items_per_page=10) : DealsResultset |
||
123 | |||
124 | /** |
||
125 | * @param \DateTime $dateFrom |
||
126 | * @param \DateTime $dateTo |
||
127 | * @param int $merchantID |
||
128 | * @return array of Transaction |
||
129 | */ |
||
130 | public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()) : array |
||
155 | |||
156 | /** |
||
157 | * @param \DateTime $dateFrom |
||
158 | * @param \DateTime $dateTo |
||
159 | * @param int $merchantID |
||
160 | * @return array of Stat |
||
161 | */ |
||
162 | public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0) : array |
||
166 | |||
167 | |||
168 | /** |
||
169 | * @param array $params |
||
170 | * |
||
171 | * @return ProductsResultset |
||
172 | */ |
||
173 | public function getProducts(array $params = []): ProductsResultset |
||
178 | |||
179 | public function getTrackingParameter(){ |
||
182 | } |
||
183 |
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.