Conditions | 11 |
Paths | 6 |
Total Lines | 31 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
57 | public function facetwp_index_row_data( $rows, $params ) { |
||
58 | switch ( $params['facet']['source'] ) { |
||
59 | case 'cf/price': |
||
60 | // only convert a price to the base currency if the setting is active. |
||
61 | // If $rows is empty then there is no base currency set. |
||
62 | if ( true === lsx_currencies()->convert_to_single && empty( $rows ) ) { |
||
63 | lsx_currencies()->frontend->set_defaults(); |
||
64 | $additional_prices = get_post_meta( $params['defaults']['post_id'], 'additional_prices', false ); |
||
65 | |||
66 | if ( ! empty( $additional_prices ) && isset( $additional_prices[0] ) && ! empty( $additional_prices[0] ) && ! empty( lsx_currencies()->frontend->rates ) ) { |
||
67 | $row_currency = $additional_prices[0]['currency']; |
||
68 | $row_value = (int) $additional_prices[0]['amount']; |
||
69 | if ( '' !== $row_value && null !== $row_value ) { |
||
70 | $current_currency = lsx_currencies()->frontend->current_currency; |
||
71 | $usd_value = $row_value / lsx_currencies()->frontend->rates->$row_currency; |
||
72 | if ( $row_currency !== $current_currency ) { |
||
73 | $usd_value = $usd_value * lsx_currencies()->frontend->rates->$current_currency; |
||
74 | } |
||
75 | $new_row = $params['defaults']; |
||
76 | $new_row['facet_value'] = round( $usd_value, 0 ); |
||
77 | $new_row['facet_display_value'] = round( $usd_value, 0 ); |
||
78 | $rows[] = $new_row; |
||
79 | } |
||
80 | } |
||
81 | } |
||
82 | break; |
||
83 | |||
84 | default: |
||
85 | break; |
||
86 | } |
||
87 | return $rows; |
||
88 | } |
||
122 |