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 | ||
| 20 | trait AdminPdfLetterControllerTrait | ||
| 21 | { | ||
| 22 | use AbstractControllerTrait; | ||
| 23 | |||
| 24 | /** | ||
| 25 | * @var string | ||
| 26 | */ | ||
| 27 | protected $letterType; | ||
| 28 | |||
| 29 | /** | ||
| 30 | * @var RecordManager | ||
| 31 | */ | ||
| 32 | protected $parentManager; | ||
| 33 | |||
| 34 | /** | ||
| 35 | * @var Record | ||
| 36 | */ | ||
| 37 | protected $parent; | ||
| 38 | |||
| 39 | |||
| 40 | public function upload() | ||
| 70 | |||
| 71 | View Code Duplication | public function downloadExample() | |
| 82 | |||
| 83 | View Code Duplication | public function downloadBlank() | |
| 94 | |||
| 95 | /** | ||
| 96 | * @param Record $parent | ||
| 97 | * @param $message | ||
| 98 | * @param string $type | ||
| 99 | */ | ||
| 100 | protected function flashRedirectLetter($parent, $message, $type = 'success') | ||
| 109 | |||
| 110 | /** | ||
| 111 | * @param Record $parent | ||
| 112 | * @return mixed | ||
| 113 | */ | ||
| 114 | protected function getPdfLettersPageUrl($parent) | ||
| 118 | |||
| 119 | /** | ||
| 120 | * @param Record $parent | ||
| 121 | * @return mixed | ||
| 122 | */ | ||
| 123 | protected function getPdfLettersPageController($parent) | ||
| 127 | |||
| 128 | /** | ||
| 129 | * @return mixed | ||
| 130 | */ | ||
| 131 | protected function viewCheckItem() | ||
| 140 | |||
| 141 | /** | ||
| 142 | * @param $item | ||
| 143 | * @param $type | ||
| 144 | * @return PdfLetterTrait|Record | ||
| 145 | */ | ||
| 146 | protected function newPdfLetterRecordFromItemType($item, $type) | ||
| 154 | |||
| 155 | /** | ||
| 156 | * @return Record|PdfLetterTrait | ||
| 157 | */ | ||
| 158 | protected function newPdfLetterRecord() | ||
| 162 | |||
| 163 | /** | ||
| 164 | * @return RecordManager | ||
| 165 | */ | ||
| 166 | protected function getParentManager() | ||
| 170 | |||
| 171 | /** | ||
| 172 | * @return Record | ||
| 173 | */ | ||
| 174 | protected function getParent() | ||
| 178 | |||
| 179 | /** | ||
| 180 | * @return string | ||
| 181 | */ | ||
| 182 | protected function getLetterType() | ||
| 186 | |||
| 187 | /** | ||
| 188 | * Called before action | ||
| 189 | */ | ||
| 190 | protected function parseRequestPdfLetter() | ||
| 198 | |||
| 199 | protected function checkRequestForParent() | ||
| 208 | |||
| 209 | protected function checkRequestForItem() | ||
| 214 | |||
| 215 | /** | ||
| 216 | * @param PdfLetterTrait $letter | ||
| 217 | */ | ||
| 218 | protected function checkRequestSetFromLetter($letter) | ||
| 224 | |||
| 225 | /** | ||
| 226 | * @inheritdoc | ||
| 227 | */ | ||
| 228 | protected function setBreadcrumbs() | ||
| 235 | } | ||
| 236 | 
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: