Conditions | 5 |
Paths | 9 |
Total Lines | 60 |
Code Lines | 42 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
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 |
||
76 | public static function wcsatt_stt_fields( $index, $scheme_data, $post_id ) { |
||
77 | if ( ! empty( $scheme_data ) ) { |
||
78 | $subscription_sign_up_fee = ! empty( $scheme_data[ 'subscription_sign_up_fee' ] ) ? $scheme_data[ 'subscription_sign_up_fee' ] : ''; |
||
79 | $subscription_trial_length = isset( $scheme_data[ 'subscription_trial_length' ] ) ? $scheme_data[ 'subscription_trial_length' ] : 0; |
||
80 | $subscription_trial_period = isset( $scheme_data[ 'subscription_trial_period' ] ) ? $scheme_data[ 'subscription_trial_period' ] : ''; |
||
81 | } else { |
||
82 | $subscription_sign_up_fee = ''; |
||
83 | $subscription_trial_length = 0; |
||
84 | $subscription_trial_period = ''; |
||
85 | } |
||
86 | |||
87 | echo '<div class="options_group subscription_scheme_product_data sign_up_trial_scheme">'; |
||
88 | |||
89 | // Sign-up Fee |
||
90 | woocommerce_wp_text_input( array( |
||
91 | 'id' => '_subscription_sign_up_fee', |
||
92 | 'class' => 'wc_input_subscription_intial_price', |
||
93 | // translators: %s is a currency symbol / code |
||
94 | 'label' => sprintf( __( 'Sign-up Fee (%s)', WCSATT_STT::TEXT_DOMAIN ), get_woocommerce_currency_symbol() ), |
||
95 | 'placeholder' => _x( 'e.g. 9.90', 'example price', WCSATT_STT::TEXT_DOMAIN ), |
||
96 | '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 ), |
||
97 | 'desc_tip' => true, |
||
98 | 'type' => 'text', |
||
99 | 'custom_attributes' => array( |
||
100 | 'step' => 'any', |
||
101 | 'min' => '0', |
||
102 | ), |
||
103 | 'name' => 'wcsatt_schemes[' . $index . '][subscription_sign_up_fee]', |
||
104 | 'value' => $subscription_sign_up_fee |
||
105 | ) ); |
||
106 | |||
107 | echo '<div class="subscription_trial">'; |
||
108 | |||
109 | // Trial Length |
||
110 | woocommerce_wp_text_input( array( |
||
111 | 'id' => '_subscription_trial_length', |
||
112 | 'class' => 'wc_input_subscription_trial_length', |
||
113 | 'label' => __( 'Free Trial', WCSATT_STT::TEXT_DOMAIN ), |
||
114 | 'name' => 'wcsatt_schemes[' . $index . '][subscription_trial_length]', |
||
115 | 'value' => $subscription_trial_length |
||
116 | ) ); |
||
117 | |||
118 | // Trial Period |
||
119 | woocommerce_wp_select( array( |
||
120 | 'id' => '_subscription_trial_period', |
||
121 | 'class' => 'wc_input_subscription_trial_period', |
||
122 | 'label' => __( 'Subscription Trial Period', WCSATT_STT::TEXT_DOMAIN ), |
||
123 | 'options' => wcs_get_available_time_periods(), |
||
124 | // translators: placeholder is trial period validation message if passed an invalid value (e.g. "Trial period can not exceed 4 weeks") |
||
125 | '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() ), |
||
126 | 'desc_tip' => true, |
||
127 | 'value' => WC_Subscriptions_Product::get_trial_period( $post_id ), // Explicitly set value in to ensure backward compatibility |
||
128 | 'name' => 'wcsatt_schemes[' . $index . '][subscription_trial_period]', |
||
129 | 'value' => $subscription_trial_period |
||
130 | ) ); |
||
131 | |||
132 | echo '</div>'; |
||
133 | |||
134 | echo '</div>'; |
||
135 | } // END wcsatt_stt_fields() |
||
136 | |||
187 |