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() |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @param Record $item |
||
| 51 | */ |
||
| 52 | public function populateFromItem($item) |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @inheritdoc |
||
| 60 | * Used to decode html entities to proper chars |
||
| 61 | */ |
||
| 62 | public function getFrom() |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @return string |
||
| 69 | */ |
||
| 70 | public function getPreviewBody() |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @return string |
||
| 77 | */ |
||
| 78 | public function getBody() |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @return string |
||
| 85 | */ |
||
| 86 | public function getSubject() |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @return array |
||
| 93 | */ |
||
| 94 | public function getTos() |
||
| 109 | |||
| 110 | /** |
||
| 111 | * @return mixed |
||
| 112 | */ |
||
| 113 | 1 | public function insert() |
|
| 120 | |||
| 121 | public function delete() |
||
| 126 | |||
| 127 | public function clearAttachments() |
||
| 131 | |||
| 132 | |||
| 133 | /** |
||
| 134 | * @param Message $message |
||
| 135 | */ |
||
| 136 | public function buildMailMessageAttachments(&$message) |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @return array|null |
||
| 148 | */ |
||
| 149 | protected function getCustomArgs() |
||
| 157 | |||
| 158 | /** |
||
| 159 | * @param null $value |
||
| 160 | * @return bool |
||
| 161 | */ |
||
| 162 | public function IsHTML($value = null) |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @return mixed |
||
| 173 | */ |
||
| 174 | View Code Duplication | public function getActivitiesByEmail() |
|
| 187 | |||
| 188 | /** |
||
| 189 | * @return mixed |
||
| 190 | */ |
||
| 191 | View Code Duplication | public function getLinksByEmail() |
|
| 204 | |||
| 205 | /** |
||
| 206 | * @param Mailer $mailer |
||
| 207 | * @param Message $message |
||
| 208 | * @param $response |
||
| 209 | */ |
||
| 210 | protected function afterSend($mailer, $message, $response) |
||
| 226 | } |
||
| 227 |
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.