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 | * Here, we map the args from the input, then we make sure that we're only querying |
||
54 | * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
||
55 | * handle batch resolution of the posts. |
||
56 | * |
||
57 | * @return array |
||
58 | * @throws EE_Error |
||
59 | * @throws InvalidArgumentException |
||
60 | * @throws ReflectionException |
||
61 | * @throws InvalidDataTypeException |
||
62 | * @throws InvalidInterfaceException |
||
63 | */ |
||
64 | // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
||
65 | public function get_query_args() |
||
113 | |||
114 | |||
115 | /** |
||
116 | * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
||
117 | * friendly keys. |
||
118 | * |
||
119 | * @param array $where_args |
||
120 | * @return array |
||
121 | */ |
||
122 | public function sanitizeInputFields(array $where_args) |
||
136 | } |
||
137 |