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 |
||
7 | View Code Duplication | class BankAccountList extends MoipResource |
|
|
|||
8 | { |
||
9 | /** |
||
10 | * Path bank accounts API. |
||
11 | * |
||
12 | * @const string |
||
13 | */ |
||
14 | const PATH = 'bankaccounts'; |
||
15 | |||
16 | /** |
||
17 | * Path accounts API. |
||
18 | * |
||
19 | * @const string |
||
20 | */ |
||
21 | const PATH_ACCOUNT = 'accounts'; |
||
22 | |||
23 | /** |
||
24 | * Initialize a new instance. |
||
25 | */ |
||
26 | public function initialize() |
||
30 | |||
31 | /** |
||
32 | * Get bank accounts. |
||
33 | * |
||
34 | * @return array |
||
35 | */ |
||
36 | public function getBankAccounts() |
||
40 | |||
41 | /** |
||
42 | * Get a bank accounts list. |
||
43 | * |
||
44 | * @param string Account id. |
||
45 | * |
||
46 | * @return stdClass |
||
47 | */ |
||
48 | public function get($account_id) |
||
52 | |||
53 | protected function populate(stdClass $response) |
||
63 | } |
||
64 |
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.