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 |
||
| 16 | class PriceConnectionResolver extends AbstractConnectionResolver |
||
| 17 | { |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @return EEM_Price |
||
| 21 | * @throws EE_Error |
||
| 22 | * @throws InvalidArgumentException |
||
| 23 | * @throws InvalidDataTypeException |
||
| 24 | * @throws InvalidInterfaceException |
||
| 25 | */ |
||
| 26 | // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
||
| 27 | public function get_query() |
||
| 31 | |||
| 32 | |||
| 33 | /** |
||
| 34 | * Return an array of items from the query |
||
| 35 | * |
||
| 36 | * @return array |
||
| 37 | */ |
||
| 38 | // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
||
| 39 | public function get_items() |
||
| 45 | |||
| 46 | |||
| 47 | /** |
||
| 48 | * Determine whether the Query should execute. If it's determined that the query should |
||
| 49 | * not be run based on context such as, but not limited to, who the user is, where in the |
||
| 50 | * ResolveTree the Query is, the relation to the node the Query is connected to, etc |
||
| 51 | * Return false to prevent the query from executing. |
||
| 52 | * |
||
| 53 | * @return bool |
||
| 54 | */ |
||
| 55 | // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
||
| 56 | public function should_execute() |
||
| 64 | |||
| 65 | |||
| 66 | /** |
||
| 67 | * Here, we map the args from the input, then we make sure that we're only querying |
||
| 68 | * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
||
| 69 | * handle batch resolution of the posts. |
||
| 70 | * |
||
| 71 | * @return array |
||
| 72 | * @throws EE_Error |
||
| 73 | * @throws InvalidArgumentException |
||
| 74 | * @throws ReflectionException |
||
| 75 | * @throws InvalidDataTypeException |
||
| 76 | * @throws InvalidInterfaceException |
||
| 77 | */ |
||
| 78 | // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
||
| 79 | public function get_query_args() |
||
| 131 | |||
| 132 | |||
| 133 | /** |
||
| 134 | * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
||
| 135 | * friendly keys. |
||
| 136 | * |
||
| 137 | * @param array $where_args |
||
| 138 | * @return array |
||
| 139 | */ |
||
| 140 | public function sanitizeInputFields(array $where_args) |
||
| 160 | } |
||
| 161 |