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 |
||
| 17 | class MeetingModel extends BaseModel |
||
|
|
|||
| 18 | { |
||
| 19 | |||
| 20 | /** |
||
| 21 | * @var array |
||
| 22 | */ |
||
| 23 | private $weekendDays = []; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @var array |
||
| 27 | */ |
||
| 28 | public $form_names = []; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var array |
||
| 32 | */ |
||
| 33 | public $dbColumns = []; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var DateTime |
||
| 37 | */ |
||
| 38 | public $regOpening = NULL; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var DateTime |
||
| 42 | */ |
||
| 43 | public $regClosing = NULL; |
||
| 44 | |||
| 45 | /** @var string registration heading text */ |
||
| 46 | public $regHeading = ''; |
||
| 47 | |||
| 48 | public $eventId; |
||
| 49 | public $courseId; |
||
| 50 | |||
| 51 | private $configuration; |
||
| 52 | |||
| 53 | private $program; |
||
| 54 | private $httpEncoding; |
||
| 55 | private $dbTable; |
||
| 56 | |||
| 57 | protected $table = 'kk_meetings'; |
||
| 58 | |||
| 59 | /** Constructor */ |
||
| 60 | public function __construct(Context $database, ProgramModel $program) |
||
| 97 | |||
| 98 | /** |
||
| 99 | * @param string $encoding |
||
| 100 | */ |
||
| 101 | public function setHttpEncoding($encoding) |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Create new or return existing instance of class |
||
| 108 | * |
||
| 109 | * @return mixed instance of class |
||
| 110 | */ |
||
| 111 | public static function getInstance() |
||
| 118 | |||
| 119 | /** |
||
| 120 | * @return Nette\Database\Table\IRow |
||
| 121 | */ |
||
| 122 | public function all() |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @param int $id |
||
| 132 | * @return Nette\Database\Table\IRow |
||
| 133 | */ |
||
| 134 | public function find($id) |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Create a new record |
||
| 144 | * |
||
| 145 | * @param mixed array of data |
||
| 146 | * @return boolean |
||
| 147 | */ |
||
| 148 | public function create(array $data) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Modify record |
||
| 158 | * |
||
| 159 | * @param int $id ID of record |
||
| 160 | * @param array $db_data array of data |
||
| 161 | * @return bool |
||
| 162 | */ |
||
| 163 | public function update($id, array $data) |
||
| 169 | |||
| 170 | /** |
||
| 171 | * Delete one or multiple record/s |
||
| 172 | * |
||
| 173 | * @param int ID/s of record |
||
| 174 | * @return boolean |
||
| 175 | */ |
||
| 176 | View Code Duplication | public function delete($ids) |
|
| 183 | |||
| 184 | /** |
||
| 185 | * Return meeting data |
||
| 186 | * |
||
| 187 | * @return Nette\Database\Table\IRow |
||
| 188 | */ |
||
| 189 | public function getData($meetingId = null) |
||
| 203 | |||
| 204 | /** |
||
| 205 | * @param string $priceType cost|advance |
||
| 206 | * @return integer |
||
| 207 | */ |
||
| 208 | public function getPrice($priceType) |
||
| 217 | |||
| 218 | /** |
||
| 219 | * Render HTML Provinces <select> |
||
| 220 | * |
||
| 221 | * @param int ID of selected province |
||
| 222 | * @return string html <select> |
||
| 223 | */ |
||
| 224 | public function renderHtmlProvinceSelect($selectedProvince) |
||
| 244 | |||
| 245 | /** |
||
| 246 | * @param integer $meetingId |
||
| 247 | * @return $this |
||
| 248 | */ |
||
| 249 | public function setRegistrationHandlers($meetingId = 1) |
||
| 269 | |||
| 270 | /** |
||
| 271 | * @return string |
||
| 272 | */ |
||
| 273 | public function getRegOpening() |
||
| 277 | |||
| 278 | /** |
||
| 279 | * @param string $value |
||
| 280 | * @return $this |
||
| 281 | */ |
||
| 282 | public function setRegOpening($value = '') |
||
| 288 | |||
| 289 | /** |
||
| 290 | * @return string |
||
| 291 | */ |
||
| 292 | public function getRegClosing() |
||
| 296 | |||
| 297 | /** |
||
| 298 | * @param string $value |
||
| 299 | * @return $this |
||
| 300 | */ |
||
| 301 | public function setRegClosing($value = '') |
||
| 307 | |||
| 308 | /** |
||
| 309 | * @return string |
||
| 310 | */ |
||
| 311 | public function getRegHeading() |
||
| 315 | |||
| 316 | /** |
||
| 317 | * @param string $value |
||
| 318 | * @return $this |
||
| 319 | */ |
||
| 320 | public function setRegHeading($value = '') |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Is registration open? |
||
| 329 | * |
||
| 330 | * @return boolean |
||
| 331 | */ |
||
| 332 | public function isRegOpen($debug = false) |
||
| 336 | |||
| 337 | /** |
||
| 338 | * @param integer $id |
||
| 339 | * @return string |
||
| 340 | */ |
||
| 341 | public function getProvinceNameById($id) |
||
| 350 | |||
| 351 | /** |
||
| 352 | * @return Row |
||
| 353 | */ |
||
| 354 | public function findEventId() |
||
| 362 | |||
| 363 | /** |
||
| 364 | * @return Row |
||
| 365 | */ |
||
| 366 | public function findCourseId() |
||
| 374 | |||
| 375 | /** |
||
| 376 | * @param integer|string $meetingId |
||
| 377 | * @return ActiveRow |
||
| 378 | */ |
||
| 379 | public function getPlaceAndYear($meetingId) |
||
| 389 | |||
| 390 | /** |
||
| 391 | * @return ActiveRow |
||
| 392 | */ |
||
| 393 | public function getMenuItems() |
||
| 404 | |||
| 405 | /** |
||
| 406 | * @return integer |
||
| 407 | */ |
||
| 408 | public function getLastMeetingId() |
||
| 417 | |||
| 418 | } |
||
| 419 |
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.