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 |
||
| 12 | class MeetingPresenter extends BasePresenter |
||
| 13 | { |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Prepare initial values |
||
| 17 | */ |
||
| 18 | public function __construct(MeetingModel $model) |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @return void |
||
| 25 | */ |
||
| 26 | View Code Duplication | public function actionCreate() |
|
| 42 | |||
| 43 | /** |
||
| 44 | * @param integer $id |
||
| 45 | * @return void |
||
| 46 | */ |
||
| 47 | View Code Duplication | public function actionUpdate($id) |
|
| 62 | |||
| 63 | /** |
||
| 64 | * Delete item |
||
| 65 | * @param int $id of item |
||
| 66 | * @return void |
||
| 67 | */ |
||
| 68 | public function actionDelete($id) |
||
| 69 | { |
||
| 70 | try { |
||
| 71 | $result = $this->getModel()->delete($id); |
||
| 72 | Debugger::log('Destroying of meeting('. $id .') successfull, result: ' . json_encode($result), Debugger::INFO); |
||
| 73 | $this->flashMessage('Položka byla úspěšně smazána', 'ok'); |
||
| 74 | } catch(Exception $e) { |
||
| 75 | Debugger::log('Destroying of meeting('. $id .') failed, result: ' . $e->getMessage(), Debugger::ERROR); |
||
| 76 | $this->flashMessage('Destroying of meeting failed, result: ' . $e->getMessage(), 'error'); |
||
| 77 | } |
||
| 78 | |||
| 79 | $this->redirect('Meeting:listing'); |
||
| 80 | } |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @return void |
||
| 84 | */ |
||
| 85 | public function renderNew() |
||
| 95 | |||
| 96 | /** |
||
| 97 | * @return void |
||
| 98 | */ |
||
| 99 | public function renderEdit($id) |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Render entire page |
||
| 115 | * @return void |
||
| 116 | */ |
||
| 117 | public function renderListing() |
||
| 131 | |||
| 132 | } |
||
| 133 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: