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 |
||
7 | View Code Duplication | class InstallCommand extends AbstractInitializeCommand |
|
|
|||
8 | { |
||
9 | /** |
||
10 | * The console command name. |
||
11 | * |
||
12 | * @var string |
||
13 | */ |
||
14 | protected $name = 'app:install'; |
||
15 | |||
16 | /** |
||
17 | * The console command description. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $description = 'Install the application according to current environment'; |
||
22 | |||
23 | /** |
||
24 | * Create a new command instance. |
||
25 | * |
||
26 | * @param Illuminate\Contracts\Container\Container $container |
||
27 | * @return void |
||
28 | */ |
||
29 | 102 | public function __construct(Container $container) |
|
30 | { |
||
31 | 102 | $this->signature = 'app:install |
|
32 | {--root : Run commands which requires root privileges} |
||
33 | {--o|options=* : Run commands for custom options'.$this->getOptionsConfig($container).'}'; |
||
34 | 102 | ||
35 | parent::__construct(); |
||
36 | 102 | } |
|
37 | |||
38 | /** |
||
39 | * Returns instance of Install class which defines initializing runner chain. |
||
40 | * |
||
41 | * {@inheritdoc} |
||
42 | */ |
||
43 | protected function getInitializerInstance(Container $container) |
||
47 | |||
48 | protected function title(): string |
||
52 | |||
53 | protected function getOptionsConfig(Container $container) |
||
64 | } |
||
65 |
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.