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 |
||
8 | View Code Duplication | class TimestampResult implements ResultInterface |
|
|
|||
9 | { |
||
10 | /** @var string response status */ |
||
11 | private $status; |
||
12 | |||
13 | /** @var array file */ |
||
14 | private $file; |
||
15 | |||
16 | /** |
||
17 | * Fields expected in response |
||
18 | * @return array |
||
19 | */ |
||
20 | 2 | public function getFields() |
|
27 | |||
28 | /** |
||
29 | * @return string |
||
30 | */ |
||
31 | 1 | public function getStatus() |
|
35 | |||
36 | /** |
||
37 | * @param string $status |
||
38 | */ |
||
39 | 1 | public function setStatus($status) |
|
43 | |||
44 | /** |
||
45 | * @return array |
||
46 | */ |
||
47 | 1 | public function getFile() |
|
51 | |||
52 | /** |
||
53 | * @param array $file |
||
54 | */ |
||
55 | 1 | public function setFile($file) |
|
59 | } |
||
60 |
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.