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 |
||
| 15 | class AttendeeConnectionResolver extends AbstractConnectionResolver |
||
| 16 | { |
||
| 17 | // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
||
| 18 | public function get_loader_name() |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @return EEM_Attendee |
||
| 25 | * @throws EE_Error |
||
| 26 | * @throws InvalidArgumentException |
||
| 27 | * @throws InvalidDataTypeException |
||
| 28 | * @throws InvalidInterfaceException |
||
| 29 | */ |
||
| 30 | // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
||
| 31 | public function get_query() |
||
| 35 | |||
| 36 | |||
| 37 | /** |
||
| 38 | * Return an array of item IDs from the query |
||
| 39 | * |
||
| 40 | * @return array |
||
| 41 | */ |
||
| 42 | // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
||
| 43 | public function get_ids() |
||
| 49 | |||
| 50 | |||
| 51 | /** |
||
| 52 | * Determine whether the Query should execute. If it's determined that the query should |
||
| 53 | * not be run based on context such as, but not limited to, who the user is, where in the |
||
| 54 | * ResolveTree the Query is, the relation to the node the Query is connected to, etc |
||
| 55 | * Return false to prevent the query from executing. |
||
| 56 | * |
||
| 57 | * @return bool |
||
| 58 | */ |
||
| 59 | // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
||
| 60 | public function should_execute() |
||
| 68 | |||
| 69 | |||
| 70 | /** |
||
| 71 | * Here, we map the args from the input, then we make sure that we're only querying |
||
| 72 | * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
||
| 73 | * handle batch resolution of the posts. |
||
| 74 | * |
||
| 75 | * @return array |
||
| 76 | * @throws EE_Error |
||
| 77 | * @throws InvalidArgumentException |
||
| 78 | * @throws ReflectionException |
||
| 79 | * @throws InvalidDataTypeException |
||
| 80 | * @throws InvalidInterfaceException |
||
| 81 | */ |
||
| 82 | // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
||
| 83 | public function get_query_args() |
||
| 124 | |||
| 125 | |||
| 126 | /** |
||
| 127 | * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
||
| 128 | * friendly keys. |
||
| 129 | * |
||
| 130 | * @param array $where_args |
||
| 131 | * @return array |
||
| 132 | */ |
||
| 133 | public function sanitizeInputFields(array $where_args) |
||
| 148 | } |
||
| 149 |