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 | final class MonetaryAccountResource |
|
|
|||
8 | { |
||
9 | /** |
||
10 | * @var BunqClient |
||
11 | */ |
||
12 | private $client; |
||
13 | |||
14 | /** |
||
15 | * @param BunqClient $client |
||
16 | */ |
||
17 | public function __construct(BunqClient $client) |
||
21 | |||
22 | /** |
||
23 | * Lists all the Monetary accounts for the current user. |
||
24 | * |
||
25 | * @param integer $userId |
||
26 | * |
||
27 | * @return array |
||
28 | */ |
||
29 | public function listMonetaryAccounts($userId) |
||
35 | |||
36 | /** |
||
37 | * Gets a Monetary Account by its identifier. |
||
38 | * |
||
39 | * @param integer $userId |
||
40 | * @param integer $id |
||
41 | * |
||
42 | * @return array |
||
43 | */ |
||
44 | public function getMonetaryAccount($userId, $id) |
||
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | private function getResourceEndpoint($userId) |
||
58 | } |
||
59 |
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.