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 SiteService extends AbstractService implements ServiceInterface |
||
15 | { |
||
16 | /** |
||
17 | * @return Site[] |
||
18 | */ |
||
19 | View Code Duplication | public function getSites(): array |
|
30 | |||
31 | /** |
||
32 | * @param int $id |
||
33 | * |
||
34 | * @return Site |
||
35 | */ |
||
36 | View Code Duplication | public function getSite(int $id): Site |
|
47 | |||
48 | /** |
||
49 | * @param SitePostMessage $message |
||
50 | * |
||
51 | * @return Site |
||
52 | */ |
||
53 | public function postSite(SitePostMessage $message): Site |
||
65 | |||
66 | /** |
||
67 | * @param SiteDeleteMessage $message |
||
68 | */ |
||
69 | public function deleteSite(SiteDeleteMessage $message) |
||
75 | |||
76 | /** |
||
77 | * @param PlatformChildrenListMessage $message |
||
78 | * |
||
79 | * @return Site[] |
||
80 | */ |
||
81 | View Code Duplication | public function getPlatformChildren(PlatformChildrenListMessage $message): array |
|
92 | } |
||
93 |
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.