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 |
||
26 | class PrimaryIndexRemoverCommand extends Command |
||
27 | { |
||
28 | /** @var string */ |
||
29 | protected $name = 'couchbase:drop-primary-index'; |
||
30 | |||
31 | /** @var string */ |
||
32 | protected $description = 'Drop the given primary index associated with the current bucket.'; |
||
33 | |||
34 | /** @var DatabaseManager */ |
||
35 | protected $databaseManager; |
||
36 | |||
37 | /** @var string */ |
||
38 | protected $defaultDatabase = 'couchbase'; |
||
39 | |||
40 | /** |
||
41 | * IndexFinderCommand constructor. |
||
42 | * |
||
43 | * @param DatabaseManager $databaseManager |
||
44 | */ |
||
45 | 1 | public function __construct(DatabaseManager $databaseManager) |
|
50 | |||
51 | /** |
||
52 | * @return string[] |
||
53 | */ |
||
54 | 1 | protected function getArguments() |
|
60 | |||
61 | /** |
||
62 | * Get the console command options. |
||
63 | * |
||
64 | * @return array |
||
65 | */ |
||
66 | 1 | protected function getOptions() |
|
79 | |||
80 | /** |
||
81 | * Execute the console command |
||
82 | */ |
||
83 | 1 | View Code Duplication | public function fire() |
98 | } |
||
99 |
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.