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 |
||
| 28 | class ProgramPresenter extends BasePresenter |
||
| 29 | { |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var integer |
||
| 33 | */ |
||
| 34 | private $programId = null; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var Emailer |
||
| 38 | */ |
||
| 39 | private $emailer; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var BlockModel |
||
| 43 | */ |
||
| 44 | private $blockModel; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var MeetingModel |
||
| 48 | */ |
||
| 49 | private $meetingModel; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var ProgramRepository |
||
| 53 | */ |
||
| 54 | private $programRepository; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var IProgramFormFactory |
||
| 58 | */ |
||
| 59 | private $programFormFactory; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var ProgramOverviewControl |
||
| 63 | */ |
||
| 64 | private $programOverview; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @var CategoryStylesControl |
||
| 68 | */ |
||
| 69 | private $categoryStyles; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @var ProgramVisitorsControl |
||
| 73 | */ |
||
| 74 | private $programVisitors; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * Prepare model classes and get meeting id |
||
| 78 | */ |
||
| 79 | public function __construct( |
||
| 96 | |||
| 97 | /** |
||
| 98 | * @param IProgramFormFactory $factory |
||
| 99 | */ |
||
| 100 | public function injectProgramFormFactory(IProgramFormFactory $factory) |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @return void |
||
| 107 | */ |
||
| 108 | public function startup() |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Stores program into storage |
||
| 120 | * |
||
| 121 | * @param Nette\Utils\ArrayHash $program |
||
| 122 | * @return boolean |
||
| 123 | */ |
||
| 124 | public function actionCreate(ArrayHash $program) |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Updates program in storage |
||
| 151 | * |
||
| 152 | * @param int $id |
||
| 153 | * @param Nette\Utils\ArrayHash $program |
||
| 154 | * @return boolean |
||
| 155 | */ |
||
| 156 | public function actionUpdate(int $id, ArrayHash $program) |
||
| 181 | |||
| 182 | /** |
||
| 183 | * @param integer $id |
||
| 184 | * @return void |
||
| 185 | */ |
||
| 186 | public function actionDelete($id) |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @return void |
||
| 209 | */ |
||
| 210 | public function actionMail($id) |
||
| 234 | |||
| 235 | /** |
||
| 236 | * View public program |
||
| 237 | * |
||
| 238 | * @return void |
||
| 239 | */ |
||
| 240 | public function renderPublic() |
||
| 258 | |||
| 259 | /** |
||
| 260 | * @return void |
||
| 261 | */ |
||
| 262 | public function renderListing() |
||
| 269 | |||
| 270 | /** |
||
| 271 | * @return void |
||
| 272 | */ |
||
| 273 | public function renderNew() |
||
| 278 | |||
| 279 | /** |
||
| 280 | * @param integer $id |
||
| 281 | * @return void |
||
| 282 | */ |
||
| 283 | public function renderEdit($id) |
||
| 295 | |||
| 296 | /** |
||
| 297 | * @return ProgramForm |
||
| 298 | */ |
||
| 299 | protected function createComponentProgramForm(): ProgramForm |
||
| 326 | |||
| 327 | /** |
||
| 328 | * @return AProgramOverviewControl |
||
| 329 | */ |
||
| 330 | protected function createComponentProgramOverview(): IProgramOverviewControl |
||
| 334 | |||
| 335 | /** |
||
| 336 | * @return CategoryStylesControl |
||
| 337 | */ |
||
| 338 | protected function createComponentCategoryStyles(): CategoryStylesControl |
||
| 342 | |||
| 343 | /** |
||
| 344 | * @return ProgramVisitorsControl |
||
| 345 | */ |
||
| 346 | protected function createComponentProgramVisitors(): ProgramVisitorsControl |
||
| 350 | |||
| 351 | /** |
||
| 352 | * @param ProgramOverviewControl $control |
||
| 353 | * @return $this |
||
| 354 | */ |
||
| 355 | protected function setProgramOverviewControl(IProgramOverviewControl $control) |
||
| 361 | |||
| 362 | /** |
||
| 363 | * @return Emailer |
||
| 364 | */ |
||
| 365 | protected function getEmailer(): Emailer |
||
| 369 | |||
| 370 | /** |
||
| 371 | * @param Emailer $emailer |
||
| 372 | * @return self |
||
| 373 | */ |
||
| 374 | protected function setEmailer(Emailer $emailer): self |
||
| 380 | |||
| 381 | /** |
||
| 382 | * @return BlockModel |
||
| 383 | */ |
||
| 384 | protected function getBlockModel(): BlockModel |
||
| 388 | |||
| 389 | /** |
||
| 390 | * @param BlockModel $blockModel |
||
| 391 | * @return self |
||
| 392 | */ |
||
| 393 | protected function setBlockModel(BlockModel $blockModel): self |
||
| 399 | |||
| 400 | /** |
||
| 401 | * @return MeetingModel |
||
| 402 | */ |
||
| 403 | protected function getMeetingModel(): MeetingModel |
||
| 407 | |||
| 408 | /** |
||
| 409 | * @param MeetingModel $model |
||
| 410 | * @return $this |
||
| 411 | */ |
||
| 412 | protected function setMeetingModel(MeetingModel $model): self |
||
| 418 | |||
| 419 | /** |
||
| 420 | * @return ProgramRepository |
||
| 421 | */ |
||
| 422 | protected function getProgramRepository(): ProgramRepository |
||
| 426 | |||
| 427 | /** |
||
| 428 | * @param ProgramRepository $model |
||
| 429 | * @return $this |
||
| 430 | */ |
||
| 431 | protected function setProgramRepository(ProgramRepository $repository):self |
||
| 437 | |||
| 438 | /** |
||
| 439 | * @param CategoryStylesControl $control |
||
| 440 | * |
||
| 441 | * @return self |
||
| 442 | */ |
||
| 443 | public function setCategoryStylesControl(CategoryStylesControl $control): self |
||
| 449 | |||
| 450 | /** |
||
| 451 | * @param ProgramVisitorsControl $control |
||
| 452 | * @return self |
||
| 453 | */ |
||
| 454 | public function setProgramVisitorsControl(ProgramVisitorsControl $control): self |
||
| 460 | |||
| 461 | } |
||
| 462 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.