Conditions | 18 |
Paths | 177 |
Total Lines | 166 |
Code Lines | 79 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
399 | function getpaid_item_recurring_price_help_text( $item, $currency = '', $_initial_price = false, $_recurring_price = false ) { |
||
400 | |||
401 | // Abort if it is not recurring. |
||
402 | if ( ! $item->is_recurring() ) { |
||
403 | return ''; |
||
404 | } |
||
405 | |||
406 | $initial_price = false === $_initial_price ? wpinv_price( $item->get_initial_price(), $currency ) : $_initial_price; |
||
407 | $recurring_price = false === $_recurring_price ? wpinv_price( $item->get_recurring_price(), $currency ) : $_recurring_price; |
||
408 | $period = getpaid_get_subscription_period_label( $item->get_recurring_period(), $item->get_recurring_interval(), '' ); |
||
409 | $initial_class = 'getpaid-item-initial-price'; |
||
410 | $recurring_class = 'getpaid-item-recurring-price'; |
||
411 | $bill_times = $item->get_recurring_limit(); |
||
412 | |||
413 | if ( ! empty( $bill_times ) ) { |
||
414 | $bill_times = $item->get_recurring_interval() * $bill_times; |
||
415 | $bill_times = getpaid_get_subscription_period_label( $item->get_recurring_period(), $bill_times ); |
||
416 | } |
||
417 | |||
418 | if ( $item instanceof GetPaid_Form_Item && false === $_initial_price ) { |
||
419 | $initial_price = wpinv_price( $item->get_sub_total(), $currency ); |
||
420 | $recurring_price = wpinv_price( $item->get_recurring_sub_total(), $currency ); |
||
421 | } |
||
422 | |||
423 | if ( wpinv_price( 0, $currency ) == $initial_price && wpinv_price( 0, $currency ) == $recurring_price ) { |
||
424 | return __( 'Free forever', 'invoicing' ); |
||
425 | } |
||
426 | |||
427 | // For free trial items. |
||
428 | if ( $item->has_free_trial() ) { |
||
429 | $trial_period = getpaid_get_subscription_period_label( $item->get_trial_period(), $item->get_trial_interval() ); |
||
430 | |||
431 | if ( wpinv_price( 0, $currency ) == $initial_price ) { |
||
432 | |||
433 | if ( empty( $bill_times ) ) { |
||
434 | |||
435 | return sprintf( |
||
436 | |||
437 | // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period |
||
438 | _x( 'Free for %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year)', 'invoicing' ), |
||
439 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
||
440 | "<span class='$recurring_class'>$recurring_price</span>", |
||
441 | "<span class='getpaid-item-recurring-period'>$period</span>" |
||
442 | |||
443 | ); |
||
444 | |||
445 | } |
||
446 | |||
447 | return sprintf( |
||
448 | |||
449 | // translators: $1: is the trial period, $2: is the recurring price, $3: is the susbcription period, $4: is the bill times |
||
450 | _x( 'Free for %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Free for 1 month then $120 / year for 4 years)', 'invoicing' ), |
||
451 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
||
452 | "<span class='$recurring_class'>$recurring_price</span>", |
||
453 | "<span class='getpaid-item-recurring-period'>$period</span>", |
||
454 | "<span class='getpaid-item-recurring-bill-times'>$bill_times</span>" |
||
455 | |||
456 | ); |
||
457 | |||
458 | } |
||
459 | |||
460 | if ( empty( $bill_times ) ) { |
||
461 | |||
462 | return sprintf( |
||
463 | |||
464 | // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period |
||
465 | _x( '%1$s for %2$s then %3$s / %4$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year)', 'invoicing' ), |
||
466 | "<span class='$initial_class'>$initial_price</span>", |
||
467 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
||
468 | "<span class='$recurring_class'>$recurring_price</span>", |
||
469 | "<span class='getpaid-item-recurring-period'>$period</span>" |
||
470 | |||
471 | ); |
||
472 | |||
473 | } |
||
474 | |||
475 | return sprintf( |
||
476 | |||
477 | // translators: $1: is the initial price, $2: is the trial period, $3: is the recurring price, $4: is the susbcription period, $4: is the susbcription bill times |
||
478 | _x( '%1$s for %2$s then %3$s / %4$s for %5$s', 'Item subscription amount. (e.g.: $7 for 1 month then $120 / year for 5 years)', 'invoicing' ), |
||
479 | "<span class='$initial_class'>$initial_price</span>", |
||
480 | "<span class='getpaid-item-trial-period'>$trial_period</span>", |
||
481 | "<span class='$recurring_class'>$recurring_price</span>", |
||
482 | "<span class='getpaid-item-recurring-period'>$period</span>", |
||
483 | "<span class='getpaid-item-recurring-bill-times'>$bill_times</span>" |
||
484 | |||
485 | ); |
||
486 | |||
487 | } |
||
488 | |||
489 | if ( $initial_price == $recurring_price ) { |
||
490 | |||
491 | if ( empty( $bill_times ) ) { |
||
492 | |||
493 | return sprintf( |
||
494 | |||
495 | // translators: $1: is the recurring price, $2: is the susbcription period |
||
496 | _x( '%1$s / %2$s', 'Item subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
||
497 | "<span class='$recurring_class'>$recurring_price</span>", |
||
498 | "<span class='getpaid-item-recurring-period'>$period</span>" |
||
499 | |||
500 | ); |
||
501 | |||
502 | } |
||
503 | |||
504 | return sprintf( |
||
505 | |||
506 | // translators: $1: is the recurring price, $2: is the susbcription period, $3: is the susbcription bill times |
||
507 | _x( '%1$s / %2$s for %3$s', 'Item subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ), |
||
508 | "<span class='$recurring_class'>$recurring_price</span>", |
||
509 | "<span class='getpaid-item-recurring-period'>$period</span>", |
||
510 | "<span class='getpaid-item-recurring-bill-times'>$bill_times</span>" |
||
511 | |||
512 | ); |
||
513 | |||
514 | } |
||
515 | |||
516 | if ( $initial_price == wpinv_price( 0, $currency ) ) { |
||
517 | |||
518 | if ( empty( $bill_times ) ) { |
||
519 | |||
520 | return sprintf( |
||
521 | |||
522 | // translators: $1: is the recurring period, $2: is the recurring price |
||
523 | _x( 'Free for %1$s then %2$s / %1$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months)', 'invoicing' ), |
||
524 | "<span class='getpaid-item-recurring-period'>$period</span>", |
||
525 | "<span class='$recurring_class'>$recurring_price</span>" |
||
526 | |||
527 | ); |
||
528 | |||
529 | } |
||
530 | |||
531 | return sprintf( |
||
532 | |||
533 | // translators: $1: is the recurring period, $2: is the recurring price, $3: is the bill times |
||
534 | _x( 'Free for %1$s then %2$s / %1$s for %3$s', 'Item subscription amount. (e.g.: Free for 3 months then $7 / 3 months for 12 months)', 'invoicing' ), |
||
535 | "<span class='getpaid-item-recurring-period'>$period</span>", |
||
536 | "<span class='$recurring_class'>$recurring_price</span>", |
||
537 | "<span class='getpaid-item-recurring-bill-times'>$bill_times</span>" |
||
538 | |||
539 | ); |
||
540 | |||
541 | } |
||
542 | |||
543 | if ( empty( $bill_times ) ) { |
||
544 | |||
545 | return sprintf( |
||
546 | |||
547 | // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period |
||
548 | _x( 'Initial payment of %1$s then %2$s / %3$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year)', 'invoicing' ), |
||
549 | "<span class='$initial_class'>$initial_price</span>", |
||
550 | "<span class='$recurring_class'>$recurring_price</span>", |
||
551 | "<span class='getpaid-item-recurring-period'>$period</span>" |
||
552 | |||
553 | ); |
||
554 | |||
555 | } |
||
556 | |||
557 | return sprintf( |
||
558 | |||
559 | // translators: $1: is the initial price, $2: is the recurring price, $3: is the susbcription period, $4: is the susbcription bill times |
||
560 | _x( 'Initial payment of %1$s then %2$s / %3$s for %4$s', 'Item subscription amount. (e.g.: Initial payment of $7 then $120 / year for 4 years)', 'invoicing' ), |
||
561 | "<span class='$initial_class'>$initial_price</span>", |
||
562 | "<span class='$recurring_class'>$recurring_price</span>", |
||
563 | "<span class='getpaid-item-recurring-period'>$period</span>", |
||
564 | "<span class='getpaid-item-recurring-bill-times'>$bill_times</span>" |
||
565 | |||
569 |