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 |
||
| 12 | class SetAutoIncrementCommand extends Command |
||
| 13 | { |
||
| 14 | use DatabaseInfo; |
||
| 15 | use GetAttribute; |
||
| 16 | use UpdateAttribute; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * The name and signature of the console command. |
||
| 20 | * |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | protected $signature = 'db:set-auto-increment |
||
| 24 | {--tables=* : The table(s) for which auto increment should be set} |
||
| 25 | {--value= : The auto increment value to be set}'; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * The console command description. |
||
| 29 | * |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | protected $description = 'Set auto increment for database table(s)'; |
||
| 33 | |||
| 34 | /** @var array */ |
||
| 35 | protected $skipTables; |
||
| 36 | |||
| 37 | /** @var array */ |
||
| 38 | protected $onlyTables; |
||
| 39 | |||
| 40 | /** @var string */ |
||
| 41 | protected $mode; |
||
| 42 | |||
| 43 | /** @var string */ |
||
| 44 | protected $driver; |
||
| 45 | |||
| 46 | /** @var int */ |
||
| 47 | protected $autoIncrement; |
||
| 48 | |||
| 49 | /** @var array */ |
||
| 50 | protected $supportedDrivers = ['mysql', 'sqlite']; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * The name of the queue the job should be sent to. |
||
| 54 | * |
||
| 55 | * @var string|null |
||
| 56 | */ |
||
| 57 | public $queue = 'monitoring'; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * Create the event listener. |
||
| 61 | * |
||
| 62 | * @return void |
||
|
|
|||
| 63 | */ |
||
| 64 | public function __construct() |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Execute the console command. |
||
| 75 | * |
||
| 76 | * @return mixed |
||
| 77 | */ |
||
| 78 | public function handle() |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Update AUTO INCREMENT value in mysql tables. |
||
| 116 | * |
||
| 117 | * @param Collection $tables |
||
| 118 | * @return void |
||
| 119 | */ |
||
| 120 | View Code Duplication | protected function updateMysqlTables(Collection $tables): void |
|
| 128 | |||
| 129 | /** |
||
| 130 | * Update AUTO INCREMENT value in sqlite tables. |
||
| 131 | * |
||
| 132 | * @param Collection $tables |
||
| 133 | * @return void |
||
| 134 | */ |
||
| 135 | View Code Duplication | protected function updateSqliteTables(Collection $tables): void |
|
| 146 | } |
||
| 147 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.