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 | View Code Duplication | class GroupController extends BaseApiController |
|
|
|||
13 | { |
||
14 | /** |
||
15 | * Init new object. |
||
16 | * |
||
17 | * @param GroupRepository $repo |
||
18 | * @param CoreConfig $config |
||
19 | * @return void |
||
20 | */ |
||
21 | public function __construct(GroupRepository $repo, CoreConfig $config) |
||
25 | |||
26 | /** |
||
27 | * Insert the given model to storage. |
||
28 | * |
||
29 | * @param InsertGroup $request |
||
30 | * @return \Illuminate\Http\Response |
||
31 | */ |
||
32 | public function insert(InsertGroup $request) |
||
36 | |||
37 | /** |
||
38 | * Update the given model to storage. |
||
39 | * |
||
40 | * @param UpdateGroup $request |
||
41 | * @return \Illuminate\Http\Response |
||
42 | */ |
||
43 | public function update(UpdateGroup $request) |
||
47 | |||
48 | /** |
||
49 | * Handle an assign permissions to group request. |
||
50 | * |
||
51 | * @param AssignPermissions $request |
||
52 | * @return \Illuminate\Http\Response |
||
53 | */ |
||
54 | public function assignPermissions(AssignPermissions $request) |
||
58 | } |
||
59 |
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.