We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
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 |
||
21 | class ConnectionBuilder |
||
22 | { |
||
23 | const PREFIX = 'arrayconnection:'; |
||
24 | |||
25 | /** |
||
26 | * A simple function that accepts an array and connection arguments, and returns |
||
27 | * a connection object for use in GraphQL. It uses array offsets as pagination, |
||
28 | * so pagination will only work if the array is static. |
||
29 | * |
||
30 | * @param array $data |
||
31 | * @param array|Argument $args |
||
32 | * |
||
33 | * @return Connection |
||
34 | */ |
||
35 | 37 | public static function connectionFromArray($data, $args = []) |
|
46 | |||
47 | /** |
||
48 | * A version of `connectionFromArray` that takes a promised array, and returns a |
||
49 | * promised connection. |
||
50 | * |
||
51 | * @param mixed $dataPromise a promise |
||
52 | * @param array|Argument $args |
||
53 | * |
||
54 | * @return mixed a promise |
||
55 | */ |
||
56 | 7 | public static function connectionFromPromisedArray($dataPromise, $args = []) |
|
64 | |||
65 | /** |
||
66 | * Given a slice (subset) of an array, returns a connection object for use in |
||
67 | * GraphQL. |
||
68 | * |
||
69 | * This function is similar to `connectionFromArray`, but is intended for use |
||
70 | * cases where you know the cardinality of the connection, consider it too large |
||
71 | * to materialize the entire array, and instead wish pass in a slice of the |
||
72 | * total result large enough to cover the range specified in `args`. |
||
73 | * |
||
74 | * @param array $arraySlice |
||
75 | * @param array|Argument $args |
||
76 | * @param array $meta |
||
77 | * |
||
78 | * @return Connection |
||
79 | */ |
||
80 | 54 | public static function connectionFromArraySlice($arraySlice, $args, array $meta) |
|
159 | |||
160 | /** |
||
161 | * A version of `connectionFromArraySlice` that takes a promised array slice, |
||
162 | * and returns a promised connection. |
||
163 | * |
||
164 | * @param mixed $dataPromise a promise |
||
165 | * @param array|Argument $args |
||
166 | * @param array $meta |
||
167 | * |
||
168 | * @return mixed a promise |
||
169 | */ |
||
170 | 6 | public static function connectionFromPromisedArraySlice($dataPromise, $args, array $meta) |
|
178 | |||
179 | /** |
||
180 | * Return the cursor associated with an object in an array. |
||
181 | * |
||
182 | * @param array $data |
||
183 | * @param mixed $object |
||
184 | * |
||
185 | * @return null|string |
||
186 | */ |
||
187 | 2 | public static function cursorForObjectInConnection($data, $object) |
|
207 | |||
208 | /** |
||
209 | * Given an optional cursor and a default offset, returns the offset |
||
210 | * to use; if the cursor contains a valid offset, that will be used, |
||
211 | * otherwise it will be the default. |
||
212 | * |
||
213 | * @param string $cursor |
||
214 | * @param int $defaultOffset |
||
215 | * |
||
216 | * @return int |
||
217 | */ |
||
218 | 55 | public static function getOffsetWithDefault($cursor, $defaultOffset) |
|
227 | |||
228 | /** |
||
229 | * Creates the cursor string from an offset. |
||
230 | * |
||
231 | * @param $offset |
||
232 | * |
||
233 | * @return string |
||
234 | */ |
||
235 | 50 | public static function offsetToCursor($offset) |
|
239 | |||
240 | /** |
||
241 | * Redefines the offset from the cursor string. |
||
242 | * |
||
243 | * @param $cursor |
||
244 | * |
||
245 | * @return int |
||
246 | */ |
||
247 | 28 | public static function cursorToOffset($cursor) |
|
251 | |||
252 | 54 | private static function getOptionsWithDefaults(array $options, array $defaults) |
|
256 | |||
257 | 13 | private static function checkPromise($value) |
|
263 | } |
||
264 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.