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 |
||
| 13 | class NotificationRepository extends EntityRepository{ |
||
| 14 | |||
| 15 | /** |
||
| 16 | * Get all notifications that should be sent. |
||
| 17 | * @param $recipientId |
||
| 18 | * @return array of Notification |
||
| 19 | */ |
||
| 20 | View Code Duplication | public function getNotificationsToSend($recipientId){ |
|
| 33 | |||
| 34 | /** |
||
| 35 | * Get all notifications that should be sent immediately. |
||
| 36 | * @param $recipientId |
||
| 37 | * @return array of Notification |
||
| 38 | */ |
||
| 39 | View Code Duplication | public function getNotificationsToSendImmediately($recipientId){ |
|
| 53 | |||
| 54 | /** |
||
| 55 | * Get all recipients with unsent Notifications |
||
| 56 | * @return array |
||
| 57 | */ |
||
| 58 | public function getNotificationRecipientIds(){ |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Mark all notifications as sent "far in the past". This is used for users that don't want to receive any notifications. |
||
| 76 | * @param $recipientId |
||
| 77 | */ |
||
| 78 | public function markAllNotificationsAsSentFarInThePast($recipientId){ |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Get the \DateTime of the last Notification that has been sent. |
||
| 91 | * @param $recipientId |
||
| 92 | * @return \DateTime |
||
| 93 | */ |
||
| 94 | public function getLastNotificationDate($recipientId){ |
||
| 109 | } |
||
| 110 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.