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 |
||
11 | class Artisan extends Command |
||
12 | { |
||
13 | /** |
||
14 | * The console command name. |
||
15 | * |
||
16 | * @var string |
||
17 | */ |
||
18 | protected $name = 'artisan'; |
||
19 | |||
20 | /** |
||
21 | * The console command description. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $description = 'laravel artisan'; |
||
26 | |||
27 | /** |
||
28 | * no support array. |
||
29 | * |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $notSupported = ['down' => '', 'tinker' => '']; |
||
33 | |||
34 | /** |
||
35 | * $artisan. |
||
36 | * |
||
37 | * @var ArtisanContract |
||
38 | */ |
||
39 | protected $artisan; |
||
40 | |||
41 | /** |
||
42 | * __construct. |
||
43 | * |
||
44 | * @param ArtisanContract $artisan |
||
45 | */ |
||
46 | public function __construct(ArtisanContract $artisan) |
||
52 | |||
53 | 4 | /** |
|
54 | 4 | * Handle the command. |
|
55 | * |
||
56 | * @throws InvalidArgumentException |
||
57 | */ |
||
58 | public function handle() |
||
69 | 4 | ||
70 | 1 | /** |
|
71 | * need focre option. |
||
72 | 3 | * |
|
73 | 3 | * @param string $command |
|
74 | * @return string |
||
75 | */ |
||
76 | protected function fixCommand($command) |
||
90 | |||
91 | 4 | /** |
|
92 | 4 | * Get the console command options. |
|
93 | 4 | * |
|
94 | 4 | * @return array |
|
95 | 1 | */ |
|
96 | protected function getOptions() |
||
102 | } |
||
103 |
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.