| Conditions | 19 |
| Paths | > 20000 |
| Total Lines | 62 |
| Lines | 17 |
| Ratio | 27.42 % |
| 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 |
||
| 31 | public static function prepareFields(array $input) |
||
| 32 | { |
||
| 33 | $args = []; |
||
| 34 | |||
| 35 | if (array_key_exists('capacity', $input)) { |
||
| 36 | $args['DTT_reg_limit'] = (int) $input['capacity']; |
||
| 37 | } |
||
| 38 | |||
| 39 | if (! empty($input['description'])) { |
||
| 40 | $args['DTT_description'] = sanitize_text_field($input['description']); |
||
| 41 | } |
||
| 42 | |||
| 43 | View Code Duplication | if (! empty($input['endDate'])) { |
|
| 44 | $args['DTT_EVT_end'] = new DateTime(sanitize_text_field($input['endDate'])); |
||
| 45 | } |
||
| 46 | |||
| 47 | if (! empty($input['eventId'])) { |
||
| 48 | $args['EVT_ID'] = absint($input['eventId']); |
||
| 49 | View Code Duplication | } elseif (! empty($input['event'])) { |
|
| 50 | $parts = Relay::fromGlobalId(sanitize_text_field($input['event'])); |
||
| 51 | $args['EVT_ID'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
||
| 52 | } |
||
| 53 | |||
| 54 | if (array_key_exists('isPrimary', $input)) { |
||
| 55 | $args['DTT_is_primary'] = (bool) $input['isPrimary']; |
||
| 56 | } |
||
| 57 | |||
| 58 | if (array_key_exists('isTrashed', $input)) { |
||
| 59 | $args['DTT_deleted'] = (bool) $input['isTrashed']; |
||
| 60 | } |
||
| 61 | |||
| 62 | if (! empty($input['name'])) { |
||
| 63 | $args['DTT_name'] = sanitize_text_field($input['name']); |
||
| 64 | } |
||
| 65 | |||
| 66 | if (array_key_exists('order', $input)) { |
||
| 67 | $args['DTT_order'] = (int) $input['order']; |
||
| 68 | } |
||
| 69 | |||
| 70 | View Code Duplication | if (! empty($input['parent'])) { |
|
| 71 | $parts = Relay::fromGlobalId(sanitize_text_field($input['parent'])); |
||
| 72 | $args['DTT_parent'] = (! empty($parts['id']) && is_int($parts['id'])) ? $parts['id'] : null; |
||
| 73 | } |
||
| 74 | |||
| 75 | if (array_key_exists('reserved', $input)) { |
||
| 76 | $args['DTT_reserved'] = (int) $input['reserved']; |
||
| 77 | } |
||
| 78 | |||
| 79 | if (array_key_exists('sold', $input)) { |
||
| 80 | $args['DTT_sold'] = (int) $input['sold']; |
||
| 81 | } |
||
| 82 | |||
| 83 | View Code Duplication | if (! empty($input['startDate'])) { |
|
| 84 | $args['DTT_EVT_start'] = new DateTime(sanitize_text_field($input['startDate'])); |
||
| 85 | } |
||
| 86 | |||
| 87 | View Code Duplication | if (! empty($input['tickets'])) { |
|
| 88 | $args['tickets'] = array_map('sanitize_text_field', (array) $input['tickets']); |
||
| 89 | } |
||
| 90 | |||
| 91 | return $args; |
||
| 92 | } |
||
| 93 | |||
| 123 |