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 ProgramPresenter extends BasePresenter |
||
| 20 | { |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var integer |
||
| 24 | */ |
||
| 25 | private $programId = null; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var Emailer |
||
| 29 | */ |
||
| 30 | private $emailer; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var BlockModel |
||
| 34 | */ |
||
| 35 | private $blockModel; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var MeetingModel |
||
| 39 | */ |
||
| 40 | private $meetingModel; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Prepare model classes and get meeting id |
||
| 44 | */ |
||
| 45 | public function __construct( |
||
| 46 | ProgramModel $model, |
||
| 47 | Emailer $emailer, |
||
| 48 | BlockModel $blockModel, |
||
| 49 | MeetingModel $meetingModel |
||
| 50 | ) { |
||
| 51 | $this->setModel($model); |
||
|
|
|||
| 52 | $this->setEmailer($emailer); |
||
| 53 | $this->setBlockModel($blockModel); |
||
| 54 | $this->setMeetingModel($meetingModel); |
||
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @return void |
||
| 59 | */ |
||
| 60 | public function startup() |
||
| 61 | { |
||
| 62 | parent::startup(); |
||
| 63 | |||
| 64 | $meetingId = $this->getMeetingId(); |
||
| 65 | $this->getModel()->setMeetingId($meetingId); |
||
| 66 | $this->getMeetingModel()->setMeetingId($meetingId); |
||
| 67 | $this->getBlockModel()->setMeetingId($meetingId); |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @return void |
||
| 72 | */ |
||
| 73 | public function actionCreate() |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @param integer $id |
||
| 102 | * @return void |
||
| 103 | */ |
||
| 104 | public function actionUpdate($id) |
||
| 130 | |||
| 131 | /** |
||
| 132 | * @param integer $id |
||
| 133 | * @return void |
||
| 134 | */ |
||
| 135 | View Code Duplication | public function actionDelete($id) |
|
| 148 | |||
| 149 | /** |
||
| 150 | * @return void |
||
| 151 | */ |
||
| 152 | View Code Duplication | public function actionMail($id) |
|
| 169 | |||
| 170 | /** |
||
| 171 | * View public program |
||
| 172 | * |
||
| 173 | * @return void |
||
| 174 | */ |
||
| 175 | public function renderPublic() |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @return void |
||
| 197 | */ |
||
| 198 | View Code Duplication | public function renderListing() |
|
| 207 | |||
| 208 | /** |
||
| 209 | * @return void |
||
| 210 | */ |
||
| 211 | public function renderNew() |
||
| 226 | |||
| 227 | /** |
||
| 228 | * @param integer $id |
||
| 229 | * @return void |
||
| 230 | */ |
||
| 231 | public function renderEdit($id) |
||
| 250 | |||
| 251 | /** |
||
| 252 | * @return Emailer |
||
| 253 | */ |
||
| 254 | protected function getEmailer() |
||
| 258 | |||
| 259 | /** |
||
| 260 | * @param Emailer $emailer |
||
| 261 | * @return $this |
||
| 262 | */ |
||
| 263 | protected function setEmailer(Emailer $emailer) |
||
| 268 | |||
| 269 | /** |
||
| 270 | * @return BlockModel |
||
| 271 | */ |
||
| 272 | protected function getBlockModel() |
||
| 276 | |||
| 277 | /** |
||
| 278 | * @param BlockModel $blockModel |
||
| 279 | * @return $this |
||
| 280 | */ |
||
| 281 | protected function setBlockModel(BlockModel $blockModel) |
||
| 286 | |||
| 287 | /** |
||
| 288 | * @return MeetingModel |
||
| 289 | */ |
||
| 290 | protected function getMeetingModel() |
||
| 294 | |||
| 295 | /** |
||
| 296 | * @param MeetingModel $model |
||
| 297 | * @return $this |
||
| 298 | */ |
||
| 299 | protected function setMeetingModel(MeetingModel $model) |
||
| 304 | |||
| 305 | } |
||
| 306 |
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: