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 TicketMutation |
||
| 14 | { |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Maps the GraphQL input to a format that the model functions can use |
||
| 18 | * |
||
| 19 | * @param array $input Data coming from the GraphQL mutation query input |
||
| 20 | * @return array |
||
| 21 | */ |
||
| 22 | public static function prepareFields(array $input) |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Sets the related datetimes for the given ticket. |
||
| 54 | * |
||
| 55 | * @param EE_Ticket $entity The Ticket instance. |
||
| 56 | * @param array $datetimes Array of datetime IDs to relate. |
||
| 57 | */ |
||
| 58 | View Code Duplication | public static function setRelatedDatetimes($entity, array $datetimes) |
|
| 75 | |||
| 76 | /** |
||
| 77 | * Sets the related prices for the given ticket. |
||
| 78 | * |
||
| 79 | * @param EE_Ticket $entity The Ticket instance. |
||
| 80 | * @param array $prices Array of entity IDs to relate. |
||
| 81 | */ |
||
| 82 | View Code Duplication | public static function setRelatedPrices($entity, array $prices) |
|
| 99 | } |
||
| 100 |