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 |
||
| 17 | View Code Duplication | class TicketDelete extends EntityMutator |
|
| 18 | { |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Defines the mutation data modification closure. |
||
| 22 | * |
||
| 23 | * @param EEM_Ticket $model |
||
| 24 | * @param Ticket $type |
||
| 25 | * @return callable |
||
| 26 | */ |
||
| 27 | public static function mutateAndGetPayload(EEM_Ticket $model, Ticket $type) |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Deletes a ticket permanently along with its relations. |
||
| 68 | * |
||
| 69 | * @param EE_Ticket $entity |
||
| 70 | * @return bool | int |
||
| 71 | * @throws ReflectionException |
||
| 72 | * @throws InvalidArgumentException |
||
| 73 | * @throws InvalidInterfaceException |
||
| 74 | * @throws InvalidDataTypeException |
||
| 75 | * @throws EE_Error |
||
| 76 | */ |
||
| 77 | public static function deleteTicketAndRelations($entity) |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Trashes a ticket. |
||
| 91 | * |
||
| 92 | * @param EE_Ticket $entity |
||
| 93 | * @return bool | int |
||
| 94 | * @throws ReflectionException |
||
| 95 | * @throws InvalidArgumentException |
||
| 96 | * @throws InvalidInterfaceException |
||
| 97 | * @throws InvalidDataTypeException |
||
| 98 | * @throws EE_Error |
||
| 99 | */ |
||
| 100 | public static function trashTicket($entity) |
||
| 105 | } |
||
| 106 |