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 |
||
| 18 | class ResetQuotaLog extends Command |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * The name and signature of the console command. |
||
| 22 | * |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | protected $signature = 'quota:reset {date} {connection} {hits=0} {misses=0}'; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * The console command description. |
||
| 29 | * |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | protected $description = 'Reset the quotalog counters for a date and connection.'; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Create a new command instance. |
||
| 36 | * |
||
| 37 | * @return void |
||
|
|
|||
| 38 | */ |
||
| 39 | 8 | public function __construct() |
|
| 43 | |||
| 44 | /** |
||
| 45 | * Execute the console command. |
||
| 46 | * |
||
| 47 | * @return mixed |
||
| 48 | */ |
||
| 49 | 8 | public function handle() |
|
| 115 | |||
| 116 | /** |
||
| 117 | * Helper. avoid duplicate code |
||
| 118 | * Run sqlite3 update statement. |
||
| 119 | * which must have same number of params |
||
| 120 | * as sql bindings. |
||
| 121 | * |
||
| 122 | * @param string $sql |
||
| 123 | * @return void |
||
| 124 | */ |
||
| 125 | 8 | View Code Duplication | protected function doUpdateStatement($sql) |
| 137 | |||
| 138 | /** |
||
| 139 | * Helper. avoid duplicate code |
||
| 140 | * Run insert or update statement. |
||
| 141 | * |
||
| 142 | * @param string $sql |
||
| 143 | * @return void |
||
| 144 | */ |
||
| 145 | 8 | View Code Duplication | protected function doUpsertStatement($sql) |
| 158 | |||
| 159 | /** |
||
| 160 | * Get the status of a sqlite3 UPDATE operation |
||
| 161 | * from native stdClass |
||
| 162 | * |
||
| 163 | * |
||
| 164 | * @param array $changes e.g: |
||
| 165 | * [ 0 => { "changes()": 1 }] |
||
| 166 | * @return boolean |
||
| 167 | */ |
||
| 168 | 8 | protected function sqliteUpdateDidChange(array $changes) |
|
| 173 | } |
||
| 174 |
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.