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 |
||
15 | class ConversationQueryBuilder extends QueryBuilder |
||
16 | { |
||
17 | /** |
||
18 | * Only return messages that are sent from/to a specific player |
||
19 | * |
||
20 | * @param Player $player The player related to the messages |
||
21 | * @return self |
||
22 | */ |
||
23 | 1 | View Code Duplication | public function forPlayer($player) |
34 | |||
35 | /** |
||
36 | * Only return messages that are sent from/to a specific team |
||
37 | * |
||
38 | * @param Team $team The team related to the messages |
||
39 | * @return self |
||
40 | */ |
||
41 | public function forTeam($team) |
||
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.