Conditions | 10 |
Paths | 192 |
Total Lines | 36 |
Lines | 3 |
Ratio | 8.33 % |
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) |
||
23 | { |
||
24 | |||
25 | $args = []; |
||
26 | |||
27 | if (! empty($input['eventId'])) { |
||
28 | $args['EVT_ID'] = absint($input['eventId']); |
||
29 | } elseif (! empty($input['event'])) { |
||
30 | $parts = Relay::fromGlobalId($input['event']); |
||
31 | $args['EVT_ID'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
||
32 | } |
||
33 | |||
34 | if (! empty($input['name'])) { |
||
35 | $args['DTT_name'] = sanitize_text_field($input['name']); |
||
36 | } |
||
37 | |||
38 | if (! empty($input['description'])) { |
||
39 | $args['DTT_description'] = sanitize_text_field($input['description']); |
||
40 | } |
||
41 | |||
42 | if (! empty($input['startDate'])) { |
||
43 | $args['DTT_EVT_start'] = sanitize_text_field($input['startDate']); |
||
44 | } |
||
45 | |||
46 | if (! empty($input['endDate'])) { |
||
47 | $args['DTT_EVT_end'] = sanitize_text_field($input['endDate']); |
||
48 | } |
||
49 | |||
50 | View Code Duplication | if (! empty($input['tickets'])) { |
|
51 | $args['tickets'] = array_map('sanitize_text_field', (array) $input['tickets']); |
||
52 | } |
||
53 | |||
54 | // Likewise the other fields... |
||
55 | |||
56 | return $args; |
||
57 | } |
||
58 | |||
82 |