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

FormSectionMutation   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 51
Duplicated Lines 7.84 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 4
loc 51
rs 10
c 0
b 0
f 0
wmc 10
lcom 0
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
C prepareFields() 4 41 10

How to fix   Duplicated Code   

Duplicated Code

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
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