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 | trait SwitchListenerTrait |
||
16 | { |
||
17 | /** |
||
18 | * @param EventInterface $event |
||
19 | */ |
||
20 | 1 | View Code Duplication | public function handle(EventInterface $event) |
29 | |||
30 | /** |
||
31 | * Get handler method name from event. |
||
32 | * |
||
33 | * Override this method if you want to change algorithm to generate the handler method name. |
||
34 | * |
||
35 | * @param EventInterface $event |
||
36 | * |
||
37 | * @return string |
||
38 | */ |
||
39 | 1 | protected function getMethodNameFromEvent(EventInterface $event) |
|
43 | } |
||
44 |
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.