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 |
||
| 19 | class VisitorModel extends BaseModel |
||
| 20 | { |
||
| 21 | |||
| 22 | /** @var string search pattern */ |
||
| 23 | public $search; |
||
| 24 | |||
| 25 | /** @var Meeting Meeting class */ |
||
| 26 | public $Meeting; |
||
| 27 | |||
| 28 | /** @var Meal Meals class */ |
||
| 29 | public $Meals; |
||
| 30 | |||
| 31 | /** @var Program Programs class */ |
||
| 32 | public $Programs; |
||
| 33 | |||
| 34 | /** @var Blocks Blocks class */ |
||
| 35 | public $Blocks; |
||
| 36 | |||
| 37 | /** @var int meeting price */ |
||
| 38 | public $meeting_price; |
||
| 39 | |||
| 40 | /** @var int meeting advance */ |
||
| 41 | private $meeting_advance; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Array of database programs table columns |
||
| 45 | * |
||
| 46 | * @var array dbColumns[] |
||
| 47 | */ |
||
| 48 | public $dbColumns = array(); |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Array of form names |
||
| 52 | * |
||
| 53 | * @var array formNames[] |
||
| 54 | */ |
||
| 55 | public $formNames = array(); |
||
| 56 | |||
| 57 | protected $table = 'kk_visitors'; |
||
| 58 | |||
| 59 | protected $columns = [ |
||
| 60 | 'name', |
||
| 61 | 'surname', |
||
| 62 | 'nick', |
||
| 63 | 'email', |
||
| 64 | 'birthday', |
||
| 65 | 'street', |
||
| 66 | 'city', |
||
| 67 | 'postal_code', |
||
| 68 | 'group_num', |
||
| 69 | 'group_name', |
||
| 70 | 'troop_name', |
||
| 71 | 'province', |
||
| 72 | 'arrival', |
||
| 73 | 'departure', |
||
| 74 | 'comment', |
||
| 75 | 'question', |
||
| 76 | 'question2', |
||
| 77 | 'bill', |
||
| 78 | 'cost', |
||
| 79 | 'meeting', |
||
| 80 | ]; |
||
| 81 | |||
| 82 | /** konstruktor */ |
||
| 83 | public function __construct( |
||
| 124 | |||
| 125 | /** |
||
| 126 | * @return array |
||
| 127 | */ |
||
| 128 | public function getColumns() |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @param $guid |
||
| 135 | * @return ActiveRow |
||
| 136 | */ |
||
| 137 | public function findByGuid($guid) |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Create a new visitor |
||
| 144 | * |
||
| 145 | * @return string |
||
| 146 | */ |
||
| 147 | public function assemble(array $DB_data, $meals_data, $programs_data, $returnGuid = false) |
||
| 203 | |||
| 204 | /** |
||
| 205 | * Modify a visitor |
||
| 206 | * |
||
| 207 | * @param int $visitor_id ID of a visitor |
||
| 208 | * @param array $db_data Visitor's database data |
||
| 209 | * @param array $meals_data Data of meals |
||
| 210 | * @param array $programs_data Program's data |
||
| 211 | * @return mixed TRUE or array of errors |
||
| 212 | */ |
||
| 213 | public function modify(int $visitorId, array $visitor, array $meals, array $programs) |
||
| 245 | |||
| 246 | /** |
||
| 247 | * Modify a visitor |
||
| 248 | * |
||
| 249 | * @param int $visitor_id ID of a visitor |
||
| 250 | * @param array $db_data Visitor's database data |
||
| 251 | * @param array $meals_data Data of meals |
||
| 252 | * @param array $programs_data Program's data |
||
| 253 | * @return mixed TRUE or array of errors |
||
| 254 | */ |
||
| 255 | public function modifyByGuid($guid, $visitor, $meals, $programs) |
||
| 289 | |||
| 290 | /** |
||
| 291 | * @param int $visitorId |
||
| 292 | * @param int $oldProgramId |
||
| 293 | * @param int $newProgramId |
||
| 294 | * @return mixed |
||
| 295 | */ |
||
| 296 | public function updateOrCreateProgram(int $visitorId, int $oldProgramId, int $newProgramId) |
||
| 318 | |||
| 319 | /** |
||
| 320 | * Delete one or multiple record/s |
||
| 321 | * |
||
| 322 | * @param int ID/s of record |
||
| 323 | * @return boolean |
||
| 324 | */ |
||
| 325 | public function delete($id) |
||
| 334 | |||
| 335 | /** |
||
| 336 | * Set as checked one or multiple record/s |
||
| 337 | * |
||
| 338 | * @param int ID/s of record |
||
| 339 | * @param int 0 | 1 |
||
| 340 | * @return boolean |
||
| 341 | */ |
||
| 342 | public function checked($id, $value) |
||
| 351 | |||
| 352 | /** |
||
| 353 | * Get count of visitors |
||
| 354 | * |
||
| 355 | * @return integer |
||
| 356 | */ |
||
| 357 | public function getCount() |
||
| 364 | |||
| 365 | /** |
||
| 366 | * @param string $search |
||
| 367 | * @return $this |
||
| 368 | */ |
||
| 369 | public function setSearch($search) |
||
| 375 | |||
| 376 | /** |
||
| 377 | * @return string |
||
| 378 | */ |
||
| 379 | protected function getSearch() |
||
| 383 | |||
| 384 | /** |
||
| 385 | * @return string |
||
| 386 | */ |
||
| 387 | protected function buildSearchQuery() |
||
| 404 | |||
| 405 | /** |
||
| 406 | * Modify the visitor's bill |
||
| 407 | * |
||
| 408 | * @param int ID/s of visitor |
||
| 409 | * @param string type of payment (pay | advance) |
||
| 410 | * @return string error message or true |
||
| 411 | */ |
||
| 412 | public function payCharge($ids, $type) |
||
| 429 | |||
| 430 | /** |
||
| 431 | * Get recipients by ids |
||
| 432 | * |
||
| 433 | * @param mixed ID of visitor |
||
| 434 | * @return mixed result |
||
| 435 | */ |
||
| 436 | public function getRecipients($ids) |
||
| 445 | |||
| 446 | /** |
||
| 447 | * @param string|DateTime $datetime |
||
| 448 | * @return DateTime |
||
| 449 | */ |
||
| 450 | protected function convertToDateTime($datetime): DateTime |
||
| 458 | |||
| 459 | /** |
||
| 460 | * @return Row |
||
| 461 | */ |
||
| 462 | public function all() |
||
| 486 | |||
| 487 | /** |
||
| 488 | * @param array $queryId |
||
| 489 | * @return string |
||
| 490 | */ |
||
| 491 | public function getSerializedMailAddress(array $queryId = []) |
||
| 510 | |||
| 511 | /** |
||
| 512 | * @param int $id |
||
| 513 | * @return Visitor |
||
| 514 | */ |
||
| 515 | public function getBill($id) |
||
| 523 | |||
| 524 | /** |
||
| 525 | * @param int ID of visitor |
||
| 526 | * @return mixed result |
||
| 527 | */ |
||
| 528 | public function findVisitorPrograms(int $visitorId) |
||
| 536 | |||
| 537 | } |
||
| 538 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..