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 EasyMarketing extends AbstractNetwork implements NetworkInterface |
||
19 | { |
||
20 | /** |
||
21 | * @var object |
||
22 | */ |
||
23 | private $_network = null; |
||
24 | private $_username = ''; |
||
25 | private $_password = ''; |
||
26 | protected $_tracking_parameter = 'subid'; |
||
27 | private $_idSite = ''; |
||
28 | |||
29 | /** |
||
30 | * @method __construct |
||
31 | */ |
||
32 | public function __construct(string $username, string $password, string $idSite = '') |
||
41 | |||
42 | View Code Duplication | public function login(string $username, string $password, string $idSite = ''): bool |
|
63 | |||
64 | /** |
||
65 | * @return bool |
||
66 | */ |
||
67 | public function checkLogin(): bool |
||
71 | |||
72 | /** |
||
73 | * @return array of Merchants |
||
74 | * @throws \Exception |
||
75 | */ |
||
76 | public function getMerchants(): array |
||
80 | |||
81 | /** |
||
82 | * @param null $merchantID |
||
83 | * @param int $page |
||
84 | * @param int $items_per_page |
||
85 | * @return DealsResultset array of Deal |
||
86 | * @throws \Exception |
||
87 | */ |
||
88 | public function getDeals($merchantID = NULL, int $page = 0, int $items_per_page = 100): DealsResultset |
||
93 | |||
94 | /** |
||
95 | * @param \DateTime $dateFrom |
||
96 | * @param \DateTime $dateTo |
||
97 | * @param array $arrMerchantID |
||
98 | * @return array of Transaction |
||
99 | * @throws \Exception |
||
100 | */ |
||
101 | public function getSales(\DateTime $dateFrom, \DateTime $dateTo, array $arrMerchantID = array()): array |
||
152 | |||
153 | /** |
||
154 | * @param \DateTime $dateFrom |
||
155 | * @param \DateTime $dateTo |
||
156 | * @param int $merchantID |
||
157 | * @return array of Stat |
||
158 | */ |
||
159 | public function getStats(\DateTime $dateFrom, \DateTime $dateTo, int $merchantID = 0): array |
||
164 | |||
165 | |||
166 | /** |
||
167 | * @param array $params |
||
168 | * @return ProductsResultset |
||
169 | * @throws \Exception |
||
170 | */ |
||
171 | public function getProducts(array $params = []): ProductsResultset |
||
176 | |||
177 | public function getTrackingParameter() |
||
181 | |||
182 | |||
183 | } |
||
184 |
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.