Conditions | 10 |
Paths | 320 |
Total Lines | 41 |
Lines | 4 |
Ratio | 9.76 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
22 | public static function prepareFields(array $input): array |
||
23 | { |
||
24 | $args = []; |
||
25 | |||
26 | if (isset($input['id'])) { |
||
27 | $args['FSC_UUID'] = sanitize_text_field($input['id']); |
||
28 | } |
||
29 | |||
30 | |||
31 | if (isset($input['appliesTo'])) { |
||
32 | $args['FSC_appliesTo'] = sanitize_text_field($input['appliesTo']); |
||
33 | } |
||
34 | |||
35 | if (isset($input['belongsTo'])) { |
||
36 | $args['FSC_belongsTo'] = sanitize_text_field($input['belongsTo']); |
||
37 | } |
||
38 | |||
39 | if (isset($input['htmlClass'])) { |
||
40 | $args['FSC_htmlClass'] = sanitize_text_field($input['htmlClass']); |
||
41 | } |
||
42 | |||
43 | // order can be 0 |
||
44 | if (array_key_exists('order', $input)) { |
||
45 | $args['FSC_order'] = absint($input['order']); |
||
46 | } |
||
47 | |||
48 | if (isset($input['status'])) { |
||
49 | $args['FSC_status'] = sanitize_text_field($input['status']); |
||
50 | } |
||
51 | |||
52 | View Code Duplication | if (! empty($input['wpUser'])) { |
|
53 | $parts = Relay::fromGlobalId(sanitize_text_field($input['wpUser'])); |
||
54 | $args['FSC_wpUser'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
||
55 | } |
||
56 | |||
57 | return apply_filters( |
||
58 | 'FHEE__EventEspresso_core_domain_services_graphql_data_mutations__form_section_args', |
||
59 | $args, |
||
60 | $input |
||
61 | ); |
||
62 | } |
||
63 | } |
||
64 |