| Conditions | 23 | 
| Paths | 11520 | 
| Total Lines | 358 | 
| Code Lines | 339 | 
| 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  | 
            ||
| 24 |     public static function output( $post ) { | 
            ||
| 25 | global $aui_bs5;  | 
            ||
| 26 | |||
| 27 | // Prepare the item.  | 
            ||
| 28 | $item = new WPInv_Item( $post );  | 
            ||
| 29 | |||
| 30 | // Nonce field.  | 
            ||
| 31 | wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' );  | 
            ||
| 32 | |||
| 33 | // Variable prices.  | 
            ||
| 34 | $variable_prices = $item->get_variable_prices();  | 
            ||
| 35 | |||
| 36 | // Set the currency position.  | 
            ||
| 37 | $position = wpinv_currency_position();  | 
            ||
| 38 | |||
| 39 |         if ( $position == 'left_space' ) { | 
            ||
| 40 | $position = 'left';  | 
            ||
| 41 | }  | 
            ||
| 42 | |||
| 43 |         if ( $position == 'right_space' ) { | 
            ||
| 44 | $position = 'right';  | 
            ||
| 45 | }  | 
            ||
| 46 | |||
| 47 | ?>  | 
            ||
| 48 | <input type="hidden" id="_wpi_current_type" value="<?php echo esc_attr( $item->get_type( 'edit' ) ); ?>" />  | 
            ||
| 49 | <style>  | 
            ||
| 50 | #poststuff .input-group-text,  | 
            ||
| 51 |             #poststuff .form-control { | 
            ||
| 52 | border-color: #7e8993;  | 
            ||
| 53 | }  | 
            ||
| 54 | |||
| 55 |             .bsui label.col-sm-3.col-form-label { | 
            ||
| 56 | font-weight: 600;  | 
            ||
| 57 | }  | 
            ||
| 58 | </style>  | 
            ||
| 59 | <div class="bsui" style="max-width: 600px;padding-top: 10px;">  | 
            ||
| 60 | |||
| 61 | <?php do_action( 'wpinv_item_details_metabox_before_price', $item ); ?>  | 
            ||
| 62 | |||
| 63 | <div class="form-group mb-3 row">  | 
            ||
| 64 | <label class="col-sm-3 col-form-label" for="wpinv_item_price"><span><?php esc_html_e( 'Item Price', 'invoicing' ); ?></span></label>  | 
            ||
| 65 | <div class="col-sm-8">  | 
            ||
| 66 | <div class="row wpinv_hide_if_variable_pricing">  | 
            ||
| 67 | <div class="col-sm-4 getpaid-price-input mb-3">  | 
            ||
| 68 | <div class="input-group input-group-sm">  | 
            ||
| 69 | |||
| 70 | <?php if ( 'left' == $position ) : ?>  | 
            ||
| 71 | <?php if ( empty( $aui_bs5 ) ) : ?>  | 
            ||
| 72 | <div class="input-group-prepend">  | 
            ||
| 73 | <span class="input-group-text"><?php echo wp_kses_post( wpinv_currency_symbol() ); ?></span>  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 74 | </div>  | 
            ||
| 75 | <?php else : ?>  | 
            ||
| 76 | <span class="input-group-text">  | 
            ||
| 77 | <?php echo wp_kses_post( wpinv_currency_symbol() ); ?>  | 
            ||
| 78 | </span>  | 
            ||
| 79 | <?php endif; ?>  | 
            ||
| 80 | <?php endif; ?>  | 
            ||
| 81 | |||
| 82 | <input type="text" name="wpinv_item_price" id="wpinv_item_price" value="<?php echo esc_attr( getpaid_unstandardize_amount( $item->get_price( 'edit' ) ) ); ?>" placeholder="<?php echo esc_attr( wpinv_sanitize_amount( 0 ) ); ?>" class="form-control wpinv-force-integer" autocomplete="off">  | 
            ||
| 83 | |||
| 84 | <?php if ( 'left' != $position ) : ?>  | 
            ||
| 85 | <?php if ( empty( $aui_bs5 ) ) : ?>  | 
            ||
| 86 | <div class="input-group-append">  | 
            ||
| 87 | <span class="input-group-text"><?php echo wp_kses_post( wpinv_currency_symbol() ); ?></span>  | 
            ||
| 88 | </div>  | 
            ||
| 89 | <?php else : ?>  | 
            ||
| 90 | <span class="input-group-text">  | 
            ||
| 91 | <?php echo wp_kses_post( wpinv_currency_symbol() ); ?>  | 
            ||
| 92 | </span>  | 
            ||
| 93 | <?php endif; ?>  | 
            ||
| 94 | <?php endif; ?>  | 
            ||
| 95 | </div>  | 
            ||
| 96 | </div>  | 
            ||
| 97 | <div class="col-sm-4 wpinv_show_if_recurring">  | 
            ||
| 98 | <div class="mb-3 input-group input-group-sm">  | 
            ||
| 99 | <?php if ( empty( $aui_bs5 ) ) : ?>  | 
            ||
| 100 | <div class="input-group-prepend"><span class="input-group-text pl-0 pr-2 border-0 bg-transparent"><?php esc_html_e( 'every' ); ?></span></div>  | 
            ||
| 101 | <?php else : ?>  | 
            ||
| 102 | <span class="input-group-text ps-0 pe-2 border-0"><?php esc_html_e( 'every' ); ?></span>  | 
            ||
| 103 | <?php endif; ?>  | 
            ||
| 104 | <input type="number" name="wpinv_recurring_interval" id="wpinv_recurring_interval" value="<?php echo esc_attr( $item->get_recurring_interval( 'edit' ) ); ?>" placeholder="1" class="form-control rounded-1 rounded-sm">  | 
            ||
| 105 | </div>  | 
            ||
| 106 | </div>  | 
            ||
| 107 | <div class="col-sm-4 wpinv_show_if_recurring">  | 
            ||
| 108 | <?php  | 
            ||
| 109 | aui()->select(  | 
            ||
| 110 | array(  | 
            ||
| 111 | 'id' => 'wpinv_recurring_period',  | 
            ||
| 112 | 'name' => 'wpinv_recurring_period',  | 
            ||
| 113 | 'label' => __( 'Period', 'invoicing' ),  | 
            ||
| 114 | 'placeholder' => __( 'Select Period', 'invoicing' ),  | 
            ||
| 115 | 'value' => $item->get_recurring_period( 'edit' ),  | 
            ||
| 116 | 'options' => array(  | 
            ||
| 117 | 'D' => __( 'day(s)', 'invoicing' ),  | 
            ||
| 118 | 'W' => __( 'week(s)', 'invoicing' ),  | 
            ||
| 119 | 'M' => __( 'month(s)', 'invoicing' ),  | 
            ||
| 120 | 'Y' => __( 'year(s)', 'invoicing' ),  | 
            ||
| 121 | ),  | 
            ||
| 122 | ),  | 
            ||
| 123 | true  | 
            ||
| 124 | );  | 
            ||
| 125 | ?>  | 
            ||
| 126 | </div>  | 
            ||
| 127 | </div>  | 
            ||
| 128 | |||
| 129 | <div class="row">  | 
            ||
| 130 | <div class="col-sm-12">  | 
            ||
| 131 | <?php  | 
            ||
| 132 | // Variable pricing.  | 
            ||
| 133 | do_action( 'wpinv_item_details_metabox_before_variable_pricing_checkbox', $item );  | 
            ||
| 134 | |||
| 135 | aui()->input(  | 
            ||
| 136 | array(  | 
            ||
| 137 | 'id' => 'wpinv_variable_pricing',  | 
            ||
| 138 | 'name' => 'wpinv_variable_pricing',  | 
            ||
| 139 | 'type' => 'checkbox',  | 
            ||
| 140 | 'label' => apply_filters( 'wpinv_variable_pricing_toggle_text', __( 'Enable variable pricing', 'invoicing' ) ),  | 
            ||
| 141 | 'value' => '1',  | 
            ||
| 142 | 'checked' => $item->has_variable_pricing(),  | 
            ||
| 143 | 'no_wrap' => true,  | 
            ||
| 144 | 'switch' => 'sm'  | 
            ||
| 145 | ),  | 
            ||
| 146 | true  | 
            ||
| 147 | );  | 
            ||
| 148 | |||
| 149 | do_action( 'wpinv_item_details_metabox_variable_pricing_checkbox', $item );  | 
            ||
| 150 | ?>  | 
            ||
| 151 | </div>  | 
            ||
| 152 | </div>  | 
            ||
| 153 | |||
| 154 | <div class="row wpinv_hide_if_variable_pricing">  | 
            ||
| 155 | <div class="col-sm-12">  | 
            ||
| 156 | <?php  | 
            ||
| 157 | |||
| 158 | // Dynamic pricing.  | 
            ||
| 159 |                             if ( $item->supports_dynamic_pricing() ) { | 
            ||
| 160 | |||
| 161 | do_action( 'wpinv_item_details_metabox_before_dynamic_pricing_checkbox', $item );  | 
            ||
| 162 | |||
| 163 | // NYP toggle.  | 
            ||
| 164 | aui()->input(  | 
            ||
| 165 | array(  | 
            ||
| 166 | 'id' => 'wpinv_name_your_price',  | 
            ||
| 167 | 'name' => 'wpinv_name_your_price',  | 
            ||
| 168 | 'type' => 'checkbox',  | 
            ||
| 169 | 'label' => apply_filters( 'wpinv_name_your_price_toggle_text', __( 'Let customers name their price', 'invoicing' ) ),  | 
            ||
| 170 | 'value' => '1',  | 
            ||
| 171 | 'checked' => $item->user_can_set_their_price(),  | 
            ||
| 172 | 'no_wrap' => true,  | 
            ||
| 173 | 'switch' => 'sm',  | 
            ||
| 174 | ),  | 
            ||
| 175 | true  | 
            ||
| 176 | );  | 
            ||
| 177 | |||
| 178 | do_action( 'wpinv_item_details_metabox_dynamic_pricing_checkbox', $item );  | 
            ||
| 179 | }  | 
            ||
| 180 | |||
| 181 | // Subscriptions.  | 
            ||
| 182 | do_action( 'wpinv_item_details_metabox_before_subscription_checkbox', $item );  | 
            ||
| 183 | |||
| 184 | aui()->input(  | 
            ||
| 185 | array(  | 
            ||
| 186 | 'id' => 'wpinv_is_recurring',  | 
            ||
| 187 | 'name' => 'wpinv_is_recurring',  | 
            ||
| 188 | 'type' => 'checkbox',  | 
            ||
| 189 | 'label' => apply_filters( 'wpinv_is_recurring_toggle_text', __( 'Charge customers a recurring amount for this item', 'invoicing' ) ),  | 
            ||
| 190 | 'value' => '1',  | 
            ||
| 191 | 'checked' => $item->is_recurring(),  | 
            ||
| 192 | 'no_wrap' => true,  | 
            ||
| 193 | 'switch' => 'sm'  | 
            ||
| 194 | ),  | 
            ||
| 195 | true  | 
            ||
| 196 | );  | 
            ||
| 197 | do_action( 'wpinv_item_details_metabox_subscription_checkbox', $item );  | 
            ||
| 198 | |||
| 199 | ?>  | 
            ||
| 200 | <div class="wpinv_show_if_recurring">  | 
            ||
| 201 | <em><?php echo wp_kses_post( wpinv_get_recurring_gateways_text() ); ?></em>  | 
            ||
| 202 | </div>  | 
            ||
| 203 | </div>  | 
            ||
| 204 | </div>  | 
            ||
| 205 | </div>  | 
            ||
| 206 | <div class="col-sm-1 pt-2 pl-0 wpinv_hide_if_variable_pricing">  | 
            ||
| 207 | <span class="wpi-help-tip dashicons dashicons-editor-help wpinv_show_if_recurring" title="<?php esc_attr_e( 'Set the subscription price, billing interval and period.', 'invoicing' ); ?>"></span>  | 
            ||
| 208 | </div>  | 
            ||
| 209 | </div>  | 
            ||
| 210 | |||
| 211 | <?php do_action( 'wpinv_item_details_metabox_after_price', $item ); ?>  | 
            ||
| 212 | |||
| 213 | <?php if ( $item->supports_dynamic_pricing() ) : ?>  | 
            ||
| 214 | <?php do_action( 'wpinv_item_details_metabox_before_minimum_price', $item ); ?>  | 
            ||
| 215 | <div class="wpinv_show_if_dynamic wpinv_minimum_price wpinv_hide_if_variable_pricing">  | 
            ||
| 216 | |||
| 217 | <div class="form-group mb-3 row">  | 
            ||
| 218 | <label for="wpinv_minimum_price" class="col-sm-3 col-form-label">  | 
            ||
| 219 | <?php esc_html_e( 'Minimum Price', 'invoicing' ); ?>  | 
            ||
| 220 | </label>  | 
            ||
| 221 | <div class="col-sm-8">  | 
            ||
| 222 | <div class="input-group input-group-sm">  | 
            ||
| 223 | <?php if ( 'left' == $position ) : ?>  | 
            ||
| 224 | <?php if ( empty( $aui_bs5 ) ) : ?>  | 
            ||
| 225 | <div class="input-group-prepend">  | 
            ||
| 226 | <span class="input-group-text"><?php echo wp_kses_post( wpinv_currency_symbol() ); ?></span>  | 
            ||
| 227 | </div>  | 
            ||
| 228 | <?php else : ?>  | 
            ||
| 229 | <span class="input-group-text">  | 
            ||
| 230 | <?php echo wp_kses_post( wpinv_currency_symbol() ); ?>  | 
            ||
| 231 | </span>  | 
            ||
| 232 | <?php endif; ?>  | 
            ||
| 233 | <?php endif; ?>  | 
            ||
| 234 | |||
| 235 | <input type="text" name="wpinv_minimum_price" id="wpinv_minimum_price" value="<?php echo esc_attr( getpaid_unstandardize_amount( $item->get_minimum_price( 'edit' ) ) ); ?>" placeholder="<?php echo esc_attr( wpinv_sanitize_amount( 0 ) ); ?>" class="form-control wpinv-force-integer">  | 
            ||
| 236 | |||
| 237 | <?php if ( 'left' != $position ) : ?>  | 
            ||
| 238 | <?php if ( empty( $aui_bs5 ) ) : ?>  | 
            ||
| 239 | <div class="input-group-append">  | 
            ||
| 240 | <span class="input-group-text"><?php echo wp_kses_post( wpinv_currency_symbol() ); ?></span>  | 
            ||
| 241 | </div>  | 
            ||
| 242 | <?php else : ?>  | 
            ||
| 243 | <span class="input-group-text">  | 
            ||
| 244 | <?php echo wp_kses_post( wpinv_currency_symbol() ); ?>  | 
            ||
| 245 | </span>  | 
            ||
| 246 | <?php endif; ?>  | 
            ||
| 247 | <?php endif; ?>  | 
            ||
| 248 | </div>  | 
            ||
| 249 | </div>  | 
            ||
| 250 | |||
| 251 | <div class="col-sm-1 pt-2 pl-0">  | 
            ||
| 252 | <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter the minimum amount that users are allowed to set', 'invoicing' ); ?>"></span>  | 
            ||
| 253 | </div>  | 
            ||
| 254 | </div>  | 
            ||
| 255 | |||
| 256 | </div>  | 
            ||
| 257 | <?php do_action( 'wpinv_item_details_metabox_minimum_price', $item ); ?>  | 
            ||
| 258 | <?php endif; ?>  | 
            ||
| 259 | |||
| 260 | <?php do_action( 'wpinv_item_details_metabox_before_maximum_renewals', $item ); ?>  | 
            ||
| 261 | <div class="wpinv_show_if_recurring wpinv_hide_if_variable_pricing wpinv_maximum_renewals">  | 
            ||
| 262 | |||
| 263 | <div class="form-group mb-3 row">  | 
            ||
| 264 | <label for="wpinv_recurring_limit" class="col-sm-3 col-form-label">  | 
            ||
| 265 | <?php esc_html_e( 'Maximum Renewals', 'invoicing' ); ?>  | 
            ||
| 266 | </label>  | 
            ||
| 267 | <div class="col-sm-8">  | 
            ||
| 268 | <input type="number" value="<?php echo esc_attr( $item->get_recurring_limit( 'edit' ) ); ?>" placeholder="0" name="wpinv_recurring_limit" id="wpinv_recurring_limit" class="form-control form-control-sm" />  | 
            ||
| 269 | </div>  | 
            ||
| 270 | <div class="col-sm-1 pt-2 pl-0">  | 
            ||
| 271 | <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Leave empty if you want the subscription to renew until it is cancelled.', 'invoicing' ); ?>"></span>  | 
            ||
| 272 | </div>  | 
            ||
| 273 | </div>  | 
            ||
| 274 | |||
| 275 | </div>  | 
            ||
| 276 | <?php do_action( 'wpinv_item_details_metabox_maximum_renewals', $item ); ?>  | 
            ||
| 277 | |||
| 278 | <?php do_action( 'wpinv_item_details_metabox_before_free_trial', $item ); ?>  | 
            ||
| 279 | <div class="wpinv_show_if_recurring wpinv_hide_if_variable_pricing wpinv_free_trial">  | 
            ||
| 280 | |||
| 281 | <div class="form-group mb-3 row">  | 
            ||
| 282 | <label class="col-sm-3 col-form-label" for="wpinv_trial_interval"><?php defined( 'GETPAID_PAID_TRIALS_VERSION' ) ? esc_html_e( 'Free/Paid Trial', 'invoicing' ) : esc_html_e( 'Free Trial', 'invoicing' ); ?></label>  | 
            ||
| 283 | |||
| 284 | <div class="col-sm-8">  | 
            ||
| 285 | <div class="row">  | 
            ||
| 286 | <div class="col-sm-6">  | 
            ||
| 287 | <?php $value = $item->has_free_trial() ? $item->get_trial_interval( 'edit' ) : 0; ?>  | 
            ||
| 288 | |||
| 289 | <div>  | 
            ||
| 290 | <input type="number" name="wpinv_trial_interval" placeholder="0" id="wpinv_trial_interval" value="<?php echo esc_attr( $value ); ?>" class="form-control form-control-sm wpinv-force-integer">  | 
            ||
| 291 | </div>  | 
            ||
| 292 | </div>  | 
            ||
| 293 | <div class="col-sm-6">  | 
            ||
| 294 | <?php  | 
            ||
| 295 | aui()->select(  | 
            ||
| 296 | array(  | 
            ||
| 297 | 'id' => 'wpinv_trial_period',  | 
            ||
| 298 | 'name' => 'wpinv_trial_period',  | 
            ||
| 299 | 'label' => __( 'Trial Period', 'invoicing' ),  | 
            ||
| 300 | 'placeholder' => __( 'Trial Period', 'invoicing' ),  | 
            ||
| 301 | 'value' => $item->get_trial_period( 'edit' ),  | 
            ||
| 302 | 'select2' => true,  | 
            ||
| 303 | 'data-allow-clear' => 'false',  | 
            ||
| 304 | 'no_wrap' => true,  | 
            ||
| 305 | 'options' => array(  | 
            ||
| 306 | 'D' => __( 'day(s)', 'invoicing' ),  | 
            ||
| 307 | 'W' => __( 'week(s)', 'invoicing' ),  | 
            ||
| 308 | 'M' => __( 'month(s)', 'invoicing' ),  | 
            ||
| 309 | 'Y' => __( 'year(s)', 'invoicing' ),  | 
            ||
| 310 | ),  | 
            ||
| 311 | ),  | 
            ||
| 312 | true  | 
            ||
| 313 | );  | 
            ||
| 314 | ?>  | 
            ||
| 315 | |||
| 316 | </div>  | 
            ||
| 317 | </div>  | 
            ||
| 318 | </div>  | 
            ||
| 319 | |||
| 320 | <div class="col-sm-1 pt-2 pl-0">  | 
            ||
| 321 | <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'An optional period of time to wait before charging the first recurring payment.', 'invoicing' ); ?>"></span>  | 
            ||
| 322 | </div>  | 
            ||
| 323 | |||
| 324 | </div>  | 
            ||
| 325 | |||
| 326 | </div>  | 
            ||
| 327 | <?php do_action( 'wpinv_item_details_metabox__free_trial', $item ); ?>  | 
            ||
| 328 | </div>  | 
            ||
| 329 | |||
| 330 | <div class="bsui">  | 
            ||
| 331 | <?php do_action( 'wpinv_item_details_metabox_before_variable_pricing', $item ); ?>  | 
            ||
| 332 | |||
| 333 | <div class="wpinv_show_if_variable_pricing wpinv_variable_pricing">  | 
            ||
| 334 | |||
| 335 | <div id="wpinv_price_fields" class="wpinv_meta_table_wrap mb-3">  | 
            ||
| 336 | <div class="widefat getpaid_repeatable_table">  | 
            ||
| 337 | |||
| 338 | <div class="wpinv-price-option-fields getpaid-repeatables-wrap">  | 
            ||
| 339 | <?php  | 
            ||
| 340 | if ( ! empty( $variable_prices ) ) :  | 
            ||
| 341 | |||
| 342 | foreach ( $variable_prices as $key => $value ) :  | 
            ||
| 343 | $name = (isset( $value['name'] ) && ! empty( $value['name'] )) ? $value['name'] : '';  | 
            ||
| 344 | $index = (isset( $value['index'] ) && $value['index'] !== '') ? $value['index'] : $key;  | 
            ||
| 345 | $amount = isset( $value['amount'] ) ? $value['amount'] : '';  | 
            ||
| 346 | |||
| 347 | $args = apply_filters( 'wpinv_price_row_args', compact( 'name', 'amount' ), $value );  | 
            ||
| 348 | $args = wp_parse_args( $args, $value );  | 
            ||
| 349 | ?>  | 
            ||
| 350 | <div class="wpinv_variable_prices_wrapper getpaid_repeatable_row" data-key="<?php echo esc_attr( $key ); ?>">  | 
            ||
| 351 | <?php self::render_price_row( $key, $args, $item, $index ); ?>  | 
            ||
| 352 | </div>  | 
            ||
| 353 | <?php  | 
            ||
| 354 | endforeach;  | 
            ||
| 355 | else :  | 
            ||
| 356 | ?>  | 
            ||
| 357 | <div class="wpinv_variable_prices_wrapper getpaid_repeatable_row" data-key="1">  | 
            ||
| 358 | <?php self::render_price_row( 1, array(), $item, 1 ); ?>  | 
            ||
| 359 | </div>  | 
            ||
| 360 | <?php endif; ?>  | 
            ||
| 361 | |||
| 362 | <div class="wpinv-add-repeatable-row">  | 
            ||
| 363 | <div class="float-none pt-2 clear">  | 
            ||
| 364 | <button type="button" class="button-secondary getpaid-add-variable-price-row"><?php _e( 'Add New Price', 'invoicing' ); ?></button>  | 
            ||
| 365 | </div>  | 
            ||
| 366 | </div>  | 
            ||
| 367 | </div>  | 
            ||
| 368 | </div>  | 
            ||
| 369 | </div>  | 
            ||
| 370 | </div>  | 
            ||
| 371 | <?php do_action( 'wpinv_item_details_metabox_variable_pricing', $item ); ?>  | 
            ||
| 372 | </div>  | 
            ||
| 373 | |||
| 374 | <div class="bsui" style="max-width: 600px;">  | 
            ||
| 375 | <?php do_action( 'wpinv_item_details_metabox_item_details', $item ); ?>  | 
            ||
| 376 | </div>  | 
            ||
| 377 | |||
| 378 | <script type="text/html" id="tmpl-getpaid-variable-price-row">  | 
            ||
| 379 | <div class="wpinv_variable_prices_wrapper getpaid_repeatable_row" data-key="1">  | 
            ||
| 380 | <?php self::render_price_row( 1, array(), $item, 1 ); ?>  | 
            ||
| 381 | </div>  | 
            ||
| 382 | </script>  | 
            ||
| 765 |