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