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 |
||
| 14 | class EmailTraining implements ShouldQueue |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * Email the employee about the training. Then return a notification to the user that an email was sent. |
||
| 18 | * |
||
| 19 | * @param TrainingAssigned $event |
||
| 20 | * |
||
| 21 | * @return void |
||
| 22 | */ |
||
| 23 | public function handle(TrainingAssigned $event) |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @param string $date |
||
| 37 | * |
||
| 38 | * @return string |
||
| 39 | */ |
||
| 40 | private function makeDueDatePretty($date) |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @param $user |
||
| 47 | * @param $training |
||
| 48 | * @param string $dueDate |
||
| 49 | * @param $trainingUser |
||
| 50 | */ |
||
| 51 | private function sendEmail($user, $training, $dueDate, $trainingUser) |
||
| 79 | } |
||
| 80 |