| Conditions | 11 |
| Paths | 576 |
| Total Lines | 41 |
| Lines | 8 |
| Ratio | 19.51 % |
| 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 | 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 |