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 |
||
10 | View Code Duplication | class MakeV extends Command |
|
|
|||
11 | { |
||
12 | |||
13 | /** |
||
14 | * The name and signature of the console command. |
||
15 | */ |
||
16 | protected $signature = 'make:v {link : The route link} {action? : View to create} |
||
17 | {--t|type=regular : Type of route to create (regular,controller,resource)} {--m|method=get : HTTP method} |
||
18 | {--api : Route is an api route}'; |
||
19 | |||
20 | /** |
||
21 | * The console command description. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $description = 'Create a view with his corresponding route and menu entry'; |
||
26 | |||
27 | /** |
||
28 | * MakeV constructor. |
||
29 | */ |
||
30 | public function __construct() |
||
34 | |||
35 | /** |
||
36 | * Execute the console command. |
||
37 | */ |
||
38 | public function handle() |
||
43 | |||
44 | /** |
||
45 | * Obtain command. |
||
46 | * |
||
47 | * @return string |
||
48 | */ |
||
49 | protected function command() |
||
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.