Conditions | 11 |
Paths | 384 |
Total Lines | 39 |
Lines | 13 |
Ratio | 33.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 |
||
29 | public static function prepareFields(array $input) |
||
30 | { |
||
31 | $args = []; |
||
32 | |||
33 | if (! empty($input['eventId'])) { |
||
34 | $args['EVT_ID'] = absint($input['eventId']); |
||
35 | View Code Duplication | } elseif (! empty($input['event'])) { |
|
36 | $parts = Relay::fromGlobalId($input['event']); |
||
37 | $args['EVT_ID'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
||
38 | } |
||
39 | |||
40 | if (! empty($input['name'])) { |
||
41 | $args['DTT_name'] = sanitize_text_field($input['name']); |
||
42 | } |
||
43 | |||
44 | if (! empty($input['description'])) { |
||
45 | $args['DTT_description'] = sanitize_text_field($input['description']); |
||
46 | } |
||
47 | |||
48 | View Code Duplication | if (! empty($input['startDate'])) { |
|
49 | $args['DTT_EVT_start'] = new DateTime(sanitize_text_field($input['startDate'])); |
||
50 | } |
||
51 | |||
52 | View Code Duplication | if (! empty($input['endDate'])) { |
|
53 | $args['DTT_EVT_end'] = new DateTime(sanitize_text_field($input['endDate'])); |
||
54 | } |
||
55 | |||
56 | View Code Duplication | if (! empty($input['tickets'])) { |
|
57 | $args['tickets'] = array_map('sanitize_text_field', (array) $input['tickets']); |
||
58 | } |
||
59 | |||
60 | if (array_key_exists('isTrashed', $input)) { |
||
61 | $args['DTT_deleted'] = (bool) $input['isTrashed']; |
||
62 | } |
||
63 | |||
64 | // Likewise the other fields... |
||
65 | |||
66 | return $args; |
||
67 | } |
||
68 | |||
98 |