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 |
||
12 | View Code Duplication | class AutomaticCollection implements CreatableFromArray |
|
|
|||
13 | { |
||
14 | /** |
||
15 | * @var int |
||
16 | */ |
||
17 | private $delayDays; |
||
18 | |||
19 | /** |
||
20 | * @var int |
||
21 | */ |
||
22 | private $amount; |
||
23 | |||
24 | public function toArray() |
||
36 | |||
37 | /** |
||
38 | * Create an API response object from the HTTP response from the API server. |
||
39 | * |
||
40 | * @param array $data |
||
41 | * |
||
42 | * @return self |
||
43 | */ |
||
44 | 3 | public static function createFromArray(array $data) |
|
52 | } |
||
53 |
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.