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 |
||
| 36 | trait EmailTrait |
||
| 37 | { |
||
| 38 | use MailableRecordTrait; |
||
| 39 | use HasMediaTrait; |
||
| 40 | use MergeTagsRecordTrait; |
||
| 41 | |||
| 42 | public function populateFromConfig() |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @param Record $item |
||
| 55 | */ |
||
| 56 | public function populateFromItem($item) |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @inheritdoc |
||
| 64 | * Used to decode html entities to proper chars |
||
| 65 | */ |
||
| 66 | public function getFrom() |
||
| 70 | |||
| 71 | /** |
||
| 72 | * @return string |
||
| 73 | */ |
||
| 74 | public function getPreviewBody() |
||
| 78 | |||
| 79 | /** |
||
| 80 | * @return string |
||
| 81 | */ |
||
| 82 | public function getBody() |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @return string |
||
| 89 | */ |
||
| 90 | public function getSubject() |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @return array |
||
| 97 | */ |
||
| 98 | public function getTos() |
||
| 113 | |||
| 114 | /** |
||
| 115 | * @return mixed |
||
| 116 | */ |
||
| 117 | 1 | public function insert() |
|
| 124 | |||
| 125 | public function delete() |
||
| 130 | |||
| 131 | public function clearAttachments() |
||
| 135 | |||
| 136 | |||
| 137 | /** |
||
| 138 | * @param Message $message |
||
| 139 | */ |
||
| 140 | public function buildMailMessageAttachments(&$message) |
||
| 149 | |||
| 150 | /** |
||
| 151 | * @return array|null |
||
| 152 | */ |
||
| 153 | protected function getCustomArgs() |
||
| 161 | |||
| 162 | /** |
||
| 163 | * @param null $value |
||
| 164 | * @return bool |
||
| 165 | */ |
||
| 166 | public function IsHTML($value = null) |
||
| 174 | |||
| 175 | /** |
||
| 176 | * @return mixed |
||
| 177 | */ |
||
| 178 | View Code Duplication | public function getActivitiesByEmail() |
|
| 191 | |||
| 192 | /** |
||
| 193 | * @return mixed |
||
| 194 | */ |
||
| 195 | View Code Duplication | public function getLinksByEmail() |
|
| 208 | |||
| 209 | /** |
||
| 210 | * @param Mailer $mailer |
||
| 211 | * @param Message $message |
||
| 212 | * @param $response |
||
| 213 | */ |
||
| 214 | protected function afterSend($mailer, $message, $response) |
||
| 230 | } |
||
| 231 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.