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 |
||
32 | class SubuserObserver |
||
33 | { |
||
34 | /** |
||
35 | * Listen to the Subuser creating event. |
||
36 | * |
||
37 | * @param Subuser $subuser The eloquent Subuser model. |
||
38 | * @return void |
||
39 | */ |
||
40 | public function creating(Subuser $subuser) |
||
44 | |||
45 | /** |
||
46 | * Listen to the Subuser created event. |
||
47 | * |
||
48 | * @param Subuser $subuser The eloquent Subuser model. |
||
49 | * @return void |
||
50 | */ |
||
51 | View Code Duplication | public function created(Subuser $subuser) |
|
61 | |||
62 | /** |
||
63 | * Listen to the Subuser deleting event. |
||
64 | * |
||
65 | * @param Subuser $subuser The eloquent Subuser model. |
||
66 | * @return void |
||
67 | */ |
||
68 | public function deleting(Subuser $subuser) |
||
72 | |||
73 | /** |
||
74 | * Listen to the Subuser deleted event. |
||
75 | * |
||
76 | * @param Subuser $subuser The eloquent Subuser model. |
||
77 | * @return void |
||
78 | */ |
||
79 | View Code Duplication | public function deleted(Subuser $subuser) |
|
88 | } |
||
89 |
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.