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 |
||
4 | View Code Duplication | class FileRequestDeadline extends BaseModel |
|
|
|||
5 | { |
||
6 | |||
7 | /** |
||
8 | * The deadline. |
||
9 | * |
||
10 | * @var string |
||
11 | */ |
||
12 | protected $deadline; |
||
13 | |||
14 | /** |
||
15 | * The grace period allowing late uploads after deadline reached. |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $allow_late_uploads; |
||
20 | |||
21 | /** |
||
22 | * Create a new FileRequestDeadline instance |
||
23 | * |
||
24 | * @param array $data |
||
25 | */ |
||
26 | public function __construct(array $data) |
||
35 | |||
36 | /** |
||
37 | * Get the 'deadline' property of the file request deadline model. |
||
38 | * |
||
39 | * @return string |
||
40 | */ |
||
41 | public function getDeadline() |
||
45 | |||
46 | /** |
||
47 | * Get the 'allow_late_uploads' property of the file request deadline model. |
||
48 | * |
||
49 | * @return string |
||
50 | */ |
||
51 | public function getAllowLateUploads() |
||
55 | } |
||
56 |
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.