Completed
Branch FET/reg-form-builder/main (a66e69)
by
unknown
09:49 queued 19s
created

FormSectionMutation::prepareFields()   C

Complexity

Conditions 10
Paths 320

Size

Total Lines 41

Duplication

Lines 4
Ratio 9.76 %

Importance

Changes 0
Metric Value
cc 10
nc 320
nop 1
dl 4
loc 41
rs 5.3333
c 0
b 0
f 0

How to fix   Complexity   

Long Method

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:

1
<?php
2
3
namespace EventEspresso\core\domain\services\graphql\data\mutations;
4
5
use GraphQLRelay\Relay;
6
7
/**
8
 * Class FormSectionMutation
9
 *
10
 * @package       Event Espresso
11
 * @author        Manzoor Wani
12
 */
13
class FormSectionMutation
14
{
15
16
    /**
17
     * Maps the GraphQL input to a format that the model functions can use
18
     *
19
     * @param array $input Data coming from the GraphQL mutation query input
20
     * @return array
21
     */
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