Completed
Branch EDTR/master (872e60)
by
unknown
27:04 queued 17:58
created

PriceMutation::prepareFields()   F

Complexity

Conditions 11
Paths 576

Size

Total Lines 41

Duplication

Lines 8
Ratio 19.51 %

Importance

Changes 0
Metric Value
cc 11
nc 576
nop 1
dl 8
loc 41
rs 3.7388
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 PriceMutation
9
 *
10
 * @package       Event Espresso
11
 * @author        Manzoor Wani
12
 */
13
class PriceMutation
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)
23
    {
24
25
        $args = [];
26
27 View Code Duplication
        if (! empty($input['priceType'])) {
28
            $parts = Relay::fromGlobalId(sanitize_text_field($input['priceType']));
29
            $args['PRT_ID'] = ! empty($parts['id']) ? absint($parts['id']) : 0;
30
        }
31
32
        if (! empty($input['name'])) {
33
            $args['PRC_name'] = sanitize_text_field($input['name']);
34
        }
35
36
        if (! empty($input['desc'])) {
37
            $args['PRC_desc'] = sanitize_text_field($input['desc']);
38
        }
39
40
        if (! empty($input['amount'])) {
41
            $args['PRC_amount'] = floatval($input['amount']);
42
        }
43
44
        if (isset($input['isDefault'])) { // it can be false
45
            $args['PRC_is_default'] = boolval($input['isDefault']);
46
        }
47
48
        if (! empty($input['overrides'])) {
49
            $args['PRC_overrides'] = intval($input['overrides']);
50
        }
51
52
        if (! empty($input['order'])) {
53
            $args['PRC_order'] = intval($input['order']);
54
        }
55
56 View Code Duplication
        if (! empty($input['parent'])) {
57
            $parts = Relay::fromGlobalId(sanitize_text_field($input['parent']));
58
            $args['PRC_parent'] = ! empty($parts['id']) ? absint($parts['id']) : 0;
59
        }
60
61
        return $args;
62
    }
63
}
64