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 |
||
| 31 | class RegistrationPresenter extends VisitorPresenter |
||
| 32 | { |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var VisitorModel |
||
| 36 | */ |
||
| 37 | private $visitorModel; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var ProgramModel |
||
| 41 | */ |
||
| 42 | private $programModel; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var UserService |
||
| 46 | */ |
||
| 47 | private $userService; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var ProgramService |
||
| 51 | */ |
||
| 52 | private $programService; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var SettingsModel |
||
| 56 | */ |
||
| 57 | protected $settingsModel; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var boolean |
||
| 61 | */ |
||
| 62 | private $disabled = false; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var IRegistrationFormFactory |
||
| 66 | */ |
||
| 67 | private $registrationFormFactory; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var EventService |
||
| 71 | */ |
||
| 72 | protected $skautisEventService; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @param MeetingModel $meetingModel |
||
| 76 | * @param UserService $userService |
||
| 77 | * @param VisitorModel $visitorModel |
||
| 78 | * @param MealModel $mealModel |
||
| 79 | * @param ProgramModel $programModel |
||
| 80 | * @param VisitorService $visitorService |
||
| 81 | * @param SettingsModel $settingsModel |
||
| 82 | */ |
||
| 83 | public function __construct( |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @return IRegistrationFormFactory |
||
| 109 | */ |
||
| 110 | public function getRegistrationFormFactory(): IRegistrationFormFactory |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Injector |
||
| 117 | * |
||
| 118 | * @param IRegistrationFormFactory $factory |
||
| 119 | */ |
||
| 120 | |||
| 121 | protected $error = FALSE; |
||
| 122 | |||
| 123 | protected $hash = NULL; |
||
| 124 | private $item; |
||
| 125 | private $mealData; |
||
| 126 | private $user; |
||
|
|
|||
| 127 | private $event; |
||
| 128 | |||
| 129 | public function injectRegistrationFormFactory(IRegistrationFormFactory $factory) |
||
| 133 | |||
| 134 | /** |
||
| 135 | * @return void |
||
| 136 | */ |
||
| 137 | public function startup() |
||
| 159 | |||
| 160 | /** |
||
| 161 | * Process data from form |
||
| 162 | * |
||
| 163 | * @return void |
||
| 164 | */ |
||
| 165 | View Code Duplication | public function actionCreate() |
|
| 183 | |||
| 184 | /** |
||
| 185 | * @param string $guid |
||
| 186 | * @return void |
||
| 187 | */ |
||
| 188 | View Code Duplication | public function actionUpdate($guid) |
|
| 205 | |||
| 206 | /** |
||
| 207 | * @return void |
||
| 208 | */ |
||
| 209 | public function renderDefault() |
||
| 222 | |||
| 223 | /** |
||
| 224 | * @param string $guid |
||
| 225 | * @return void |
||
| 226 | */ |
||
| 227 | public function renderCheck($guid) |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @param string $guid |
||
| 244 | * @return void |
||
| 245 | */ |
||
| 246 | public function renderEdit($guid) |
||
| 261 | |||
| 262 | /** |
||
| 263 | * @return RegistrationFormControl |
||
| 264 | */ |
||
| 265 | protected function createComponentRegistrationForm(): RegistrationForm |
||
| 299 | |||
| 300 | /** |
||
| 301 | * @return VisitorEntity |
||
| 302 | */ |
||
| 303 | protected function useLoggedVisitor(): VisitorEntity |
||
| 332 | |||
| 333 | /** |
||
| 334 | * @return MealModel |
||
| 335 | */ |
||
| 336 | protected function getMealModel() |
||
| 340 | |||
| 341 | /** |
||
| 342 | * @param MealModel $model |
||
| 343 | * @return $this |
||
| 344 | */ |
||
| 345 | protected function setMealModel(MealModel $model) |
||
| 351 | |||
| 352 | /** |
||
| 353 | * @return MeetingModel |
||
| 354 | */ |
||
| 355 | protected function getMeetingModel() |
||
| 359 | |||
| 360 | /** |
||
| 361 | * @param MeetingModel $model |
||
| 362 | * @return $this |
||
| 363 | */ |
||
| 364 | protected function setMeetingModel(MeetingModel $model) |
||
| 370 | |||
| 371 | /** |
||
| 372 | * @return VisitorModel |
||
| 373 | */ |
||
| 374 | protected function getVisitorModel() |
||
| 378 | |||
| 379 | /** |
||
| 380 | * @param VisitorModel $model |
||
| 381 | * @return $this |
||
| 382 | */ |
||
| 383 | protected function setVisitorModel(VisitorModel $model) |
||
| 389 | |||
| 390 | /** |
||
| 391 | * @return ProgramModel |
||
| 392 | */ |
||
| 393 | protected function getProgramModel() |
||
| 397 | |||
| 398 | /** |
||
| 399 | * @param ProgramModel $model |
||
| 400 | * @return $this |
||
| 401 | */ |
||
| 402 | protected function setProgramModel(ProgramModel $model) |
||
| 408 | |||
| 409 | /** |
||
| 410 | * @return UserService |
||
| 411 | */ |
||
| 412 | protected function getUserService() |
||
| 416 | |||
| 417 | /** |
||
| 418 | * @param UserService $service |
||
| 419 | * @return $this |
||
| 420 | */ |
||
| 421 | protected function setUserService(UserService $service) |
||
| 427 | |||
| 428 | /** |
||
| 429 | * @return ProgramService |
||
| 430 | */ |
||
| 431 | protected function getProgramService() |
||
| 435 | |||
| 436 | /** |
||
| 437 | * @param ProgramService $service |
||
| 438 | * @return $this |
||
| 439 | */ |
||
| 440 | protected function setProgramService(ProgramService $service) |
||
| 446 | |||
| 447 | /** |
||
| 448 | * @return EventService |
||
| 449 | */ |
||
| 450 | protected function getEventService(): EventService |
||
| 454 | |||
| 455 | /** |
||
| 456 | * @param EventService $skautisEvent |
||
| 457 | * |
||
| 458 | * @return self |
||
| 459 | */ |
||
| 460 | protected function setEventService(EventService $service): self |
||
| 466 | |||
| 467 | |||
| 468 | /** |
||
| 469 | * @return SettingsModel |
||
| 470 | */ |
||
| 471 | public function getSettingsModel() |
||
| 475 | |||
| 476 | /** |
||
| 477 | * @param SettingsModel $model |
||
| 478 | * |
||
| 479 | * @return self |
||
| 480 | */ |
||
| 481 | public function setSettingsModel(SettingsModel $model): self |
||
| 487 | |||
| 488 | } |
||
| 489 |