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 |
||
14 | class Included extends Collector implements FinalCollectorInterface |
||
15 | { |
||
16 | /** |
||
17 | * The path in the final json |
||
18 | * @example |
||
19 | * path /aa/bb |
||
20 | * will be transformed to |
||
21 | * { |
||
22 | * aa : { |
||
23 | * bb: <VALUE OF RESOLVE> |
||
24 | * } |
||
25 | * } |
||
26 | * @return string |
||
27 | */ |
||
28 | 2 | public function getPath() |
|
32 | |||
33 | 2 | public function validate() |
|
39 | |||
40 | /** |
||
41 | * Convert data into jsonpatch query and save it in the data source |
||
42 | * @return mixed |
||
43 | */ |
||
44 | 2 | public function persist() |
|
53 | |||
54 | /** |
||
55 | * Fetch data |
||
56 | * @return void |
||
57 | */ |
||
58 | 4 | public function resolve() |
|
62 | } |
||
63 |
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.