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 |
||
12 | class ExpoController extends Controller |
||
13 | { |
||
14 | /** |
||
15 | * @var ExpoChannel |
||
16 | */ |
||
17 | private $expoChannel; |
||
18 | |||
19 | /** |
||
20 | * ExpoController constructor. |
||
21 | * |
||
22 | * @param ExpoChannel $expoChannel |
||
23 | */ |
||
24 | 10 | public function __construct(ExpoChannel $expoChannel) |
|
28 | |||
29 | /** |
||
30 | * Handles subscription endpoint for an expo token. |
||
31 | * |
||
32 | * @param Request $request |
||
33 | * |
||
34 | * @return \Illuminate\Http\JsonResponse |
||
35 | */ |
||
36 | 5 | public function subscribe(Request $request) |
|
71 | |||
72 | /** |
||
73 | * Handles removing subscription endpoint for the authenticated interest. |
||
74 | * |
||
75 | * @param Request $request |
||
76 | * |
||
77 | * @return JsonResponse |
||
78 | */ |
||
79 | 5 | public function unsubscribe(Request $request) |
|
111 | } |
||
112 |
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.