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