Conditions | 16 |
Paths | > 20000 |
Total Lines | 67 |
Lines | 0 |
Ratio | 0 % |
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 |
||
23 | public static function prepareFields(array $input, $mutation_name) |
||
24 | { |
||
25 | |||
26 | $args = []; |
||
27 | |||
28 | if (! empty($input['additionalLimit'])) { |
||
29 | $args['EVT_additional_limit'] = absint($input['additionalLimit']); |
||
30 | } |
||
31 | |||
32 | if (array_key_exists('allowOverflow', $input)) { |
||
33 | $args['EVT_allow_overflow'] = (bool) ($input['allowOverflow']); |
||
34 | } |
||
35 | |||
36 | if (! empty($input['desc'])) { |
||
37 | $args['EVT_desc'] = sanitize_post_field('post_content', $input['desc'], null, $context = 'db'); |
||
38 | } |
||
39 | |||
40 | if (array_key_exists('displayDesc', $input)) { |
||
41 | $args['EVT_display_desc'] = (bool) ($input['displayDesc']); |
||
42 | } |
||
43 | |||
44 | if (array_key_exists('displayTicketSelector', $input)) { |
||
45 | $args['EVT_display_ticket_selector'] = (bool) ($input['displayTicketSelector']); |
||
46 | } |
||
47 | |||
48 | if (array_key_exists('donations', $input)) { |
||
49 | $args['EVT_donations'] = (bool) ($input['donations']); |
||
50 | } |
||
51 | |||
52 | if (! empty($input['externalUrl'])) { |
||
53 | $args['EVT_external_URL'] = sanitize_text_field($input['externalUrl']); |
||
54 | } |
||
55 | |||
56 | if (array_key_exists('memberOnly', $input)) { |
||
57 | $args['EVT_member_only'] = (bool) ($input['memberOnly']); |
||
58 | } |
||
59 | |||
60 | if (! empty($input['name'])) { |
||
61 | $args['EVT_name'] = sanitize_text_field($input['name']); |
||
62 | } |
||
63 | |||
64 | if (! empty($input['order'])) { |
||
65 | $args['EVT_order'] = absint($input['order']); |
||
66 | } |
||
67 | |||
68 | if (! empty($input['phone'])) { |
||
69 | $args['EVT_phone'] = sanitize_text_field($input['phone']); |
||
70 | } |
||
71 | |||
72 | if (! empty($input['shortDesc'])) { |
||
73 | $args['EVT_short_desc'] = sanitize_post_field('post_excerpt', $input['shortDesc'], null, $context = 'db'); |
||
74 | } |
||
75 | |||
76 | if (! empty($input['timezoneString'])) { |
||
77 | $args['EVT_timezone_string'] = sanitize_text_field($input['timezoneString']); |
||
78 | } |
||
79 | |||
80 | if (! empty($input['visibleOn'])) { |
||
81 | $args['EVT_visible_on'] = new DateTime(sanitize_text_field($input['visibleOn'])); |
||
82 | } |
||
83 | |||
84 | if (! empty($input['wpUser'])) { |
||
85 | $args['EVT_wp_user'] = absint($input['wpUser']); |
||
86 | } |
||
87 | |||
88 | return $args; |
||
89 | } |
||
90 | } |
||
91 |