Conditions | 5 |
Paths | 9 |
Total Lines | 52 |
Code Lines | 38 |
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 |
||
56 | public static function wcsatt_stt_fields( $index, $scheme_data, $post_id ) { |
||
57 | if ( ! empty( $scheme_data ) ) { |
||
58 | $subscription_sign_up_fee = ! empty( $scheme_data[ 'subscription_sign_up_fee' ] ) ? $scheme_data[ 'subscription_sign_up_fee' ] : ''; |
||
59 | $subscription_trial_length = isset( $scheme_data[ 'subscription_trial_length' ] ) ? $scheme_data[ 'subscription_trial_length' ] : 0; |
||
60 | $subscription_trial_period = isset( $scheme_data[ 'subscription_trial_period' ] ) ? $scheme_data[ 'subscription_trial_period' ] : ''; |
||
61 | } else { |
||
62 | $subscription_sign_up_fee = ''; |
||
63 | $subscription_trial_length = 0; |
||
64 | $subscription_trial_period = ''; |
||
65 | } |
||
66 | |||
67 | // Sign-up Fee |
||
68 | woocommerce_wp_text_input( array( |
||
69 | 'id' => '_subscription_sign_up_fee', |
||
70 | 'class' => 'wc_input_subscription_intial_price', |
||
71 | // translators: %s is a currency symbol / code |
||
72 | 'label' => sprintf( __( 'Sign-up Fee (%s)', WCSATT_STT::TEXT_DOMAIN ), get_woocommerce_currency_symbol() ), |
||
73 | 'placeholder' => _x( 'e.g. 9.90', 'example price', WCSATT_STT::TEXT_DOMAIN ), |
||
74 | 'description' => __( 'Optionally include an amount to be charged at the outset of the subscription. The sign-up fee will be charged immediately, even if the product has a free trial or the payment dates are synced.', WCSATT_STT::TEXT_DOMAIN ), |
||
75 | 'desc_tip' => true, |
||
76 | 'type' => 'text', |
||
77 | 'custom_attributes' => array( |
||
78 | 'step' => 'any', |
||
79 | 'min' => '0', |
||
80 | ), |
||
81 | 'name' => 'wcsatt_schemes[' . $index . '][subscription_sign_up_fee]', |
||
82 | 'value' => $subscription_sign_up_fee |
||
83 | ) ); |
||
84 | |||
85 | // Trial Length |
||
86 | woocommerce_wp_text_input( array( |
||
87 | 'id' => '_subscription_trial_length', |
||
88 | 'class' => 'wc_input_subscription_trial_length', |
||
89 | 'label' => __( 'Free Trial', WCSATT_STT::TEXT_DOMAIN ), |
||
90 | 'name' => 'wcsatt_schemes[' . $index . '][subscription_trial_length]', |
||
91 | 'value' => $subscription_trial_length |
||
92 | ) ); |
||
93 | |||
94 | // Trial Period |
||
95 | woocommerce_wp_select( array( |
||
96 | 'id' => '_subscription_trial_period', |
||
97 | 'class' => 'wc_input_subscription_trial_period', |
||
98 | 'label' => __( 'Subscription Trial Period', WCSATT_STT::TEXT_DOMAIN ), |
||
99 | 'options' => wcs_get_available_time_periods(), |
||
100 | // translators: placeholder is trial period validation message if passed an invalid value (e.g. "Trial period can not exceed 4 weeks") |
||
101 | 'description' => sprintf( _x( 'An optional period of time to wait before charging the first recurring payment. Any sign up fee will still be charged at the outset of the subscription. %s', 'Trial period dropdown\'s description in pricing fields', WCSATT_STT::TEXT_DOMAIN ), WC_Subscriptions_Admin::get_trial_period_validation_message() ), |
||
102 | 'desc_tip' => true, |
||
103 | 'value' => WC_Subscriptions_Product::get_trial_period( $post_id ), // Explicitly set value in to ensure backward compatibility |
||
104 | 'name' => 'wcsatt_schemes[' . $index . '][subscription_trial_period]', |
||
105 | 'value' => $subscription_trial_period |
||
106 | ) ); |
||
107 | } // END wcsatt_stt_fields() |
||
108 | |||
159 |