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 |
||
16 | View Code Duplication | abstract class Mail extends StreamCollector implements StreamCollectorInterface |
|
|
|||
17 | { |
||
18 | /** |
||
19 | * The path in the final json |
||
20 | * @example |
||
21 | * path /aa/bb |
||
22 | * will be transformed to |
||
23 | * { |
||
24 | * aa : { |
||
25 | * bb: <VALUE OF RESOLVE> |
||
26 | * } |
||
27 | * } |
||
28 | * @return mixed |
||
29 | */ |
||
30 | 2 | public function getPath() |
|
34 | |||
35 | 2 | public function getDataFields() |
|
41 | |||
42 | /** |
||
43 | * Write data in the datasource and clean current buffer |
||
44 | * @return mixed |
||
45 | */ |
||
46 | public function stream() |
||
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.