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 | View Code Duplication | class CreateCategory extends Command |
|
|
|||
16 | { |
||
17 | use AskAndValidate; |
||
18 | |||
19 | /** |
||
20 | * The name and signature of the console command. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $signature = 'flashcard:category {--A|active= : If set, the category is going to be active.}'; |
||
25 | |||
26 | /** |
||
27 | * The console command description. |
||
28 | * |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $description = 'Create a category'; |
||
32 | |||
33 | /** |
||
34 | * @var Category |
||
35 | */ |
||
36 | protected $entity; |
||
37 | |||
38 | |||
39 | /** |
||
40 | * Instance of category model |
||
41 | * |
||
42 | * @return Model |
||
43 | */ |
||
44 | 2 | protected function getEntity(): Model |
|
54 | |||
55 | /** |
||
56 | * Execute the command line to create a new category. |
||
57 | * |
||
58 | * @return int |
||
59 | */ |
||
60 | 2 | public function handle() |
|
90 | } |
||
91 |
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.