Passed
Push — master ( eba4be...60f62d )
by Brian
09:36 queued 04:47
created

GetPaid_Meta_Box_Invoice_Subscription   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
eloc 87
c 1
b 0
f 0
dl 0
loc 109
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C output() 0 102 11
1
<?php
2
/**
3
 * Invoice Subscription Details
4
 *
5
 *
6
 */
7
8
if ( ! defined( 'ABSPATH' ) ) {
9
	exit; // Exit if accessed directly
10
}
11
12
/**
13
 * GetPaid_Meta_Box_Invoice_Subscription Class.
14
 */
15
class GetPaid_Meta_Box_Invoice_Subscription {
16
17
    /**
18
	 * Output the metabox.
19
	 *
20
	 * @param WP_Post $post
21
	 */
22
    public static function output( $post ) {
23
24
        //Fetch the invoice.
25
        $invoice = new WPInv_Invoice( $post );
26
27
        // Ensure that it is recurring.
28
        if ( ! $invoice->is_recurring() ) {
29
            return;
30
        }
31
32
        // Fetch the subscription.
33
        $subscription = wpinv_get_subscription( $invoice );
34
35
        ?>
36
            <?php if ( empty( $subscription ) ): ?>
37
                <p class="wpi-meta-row">
38
                    <?php
39
                        echo
40
                            wp_sprintf(
41
                                __( 'A new subscription will be created when the customer checks out and pays the invoice. %sView all subscriptions%s', 'invoicing' ),
42
                                '<a href="' . admin_url( 'admin.php?page=wpinv-subscriptions' ).'">',
43
                                '</a>'
44
                            );
45
                    ?>
46
                </p>
47
            <?php
48
                return; // If no subscription.
49
                endif;
50
51
                $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->period, $subscription->frequency );
0 ignored issues
show
Bug introduced by
It seems like $subscription->frequency can also be of type WP_Error; however, parameter $frequency_count of WPInv_Subscriptions::wpi...ubscription_frequency() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

51
                $frequency = WPInv_Subscriptions::wpinv_get_pretty_subscription_frequency( $subscription->period, /** @scrutinizer ignore-type */ $subscription->frequency );
Loading history...
Bug Best Practice introduced by
The property frequency does not exist on WPInv_Subscription. Since you implemented __get, consider adding a @property annotation.
Loading history...
52
                $billing   = wpinv_price(wpinv_format_amount( $subscription->recurring_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) ) . ' / ' . $frequency;
53
                $initial   = wpinv_price(wpinv_format_amount( $subscription->initial_amount ), wpinv_get_invoice_currency_code( $subscription->parent_payment_id ) );
54
                $exipired  = strtotime( $subscription->expiration, current_time( 'timestamp' ) ) < current_time( 'timestamp' );
55
            ?>
56
57
            <p class="wpi-meta-row wpi-sub-label <?php echo 'status-' . esc_attr( $subscription->status ); ?>">
58
                <?php echo $invoice->is_renewal() ? _e('Renewal Invoice', 'invoicing') : _e('Recurring Invoice', 'invoicing'); ?>
0 ignored issues
show
Bug introduced by
Are you sure the usage of _e('Recurring Invoice', 'invoicing') is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure the usage of _e('Renewal Invoice', 'invoicing') is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
59
            </p>
60
61
            <?php if ( ! empty( $subscription->id ) ) : ?>
62
                <p class="wpi-meta-row wpi-sub-id">
63
                    <label><?php _e( 'Subscription ID:', 'invoicing' ); ?></label>
64
                    <a href="<?php echo esc_url( admin_url( 'admin.php?page=wpinv-subscriptions&id=' . $subscription->id ) ); ?>" title="<?php esc_attr_e( 'View or edit subscription', 'invoicing' ); ?>" target="_blank"><?php echo $subscription->id; ?></a>
65
                </p>
66
            <?php endif; ?>
67
68
            <p class="wpi-meta-row wpi-bill-cycle">
69
                <label><?php _e( 'Billing Cycle:', 'invoicing'); ?> </label>
70
                <?php
71
72
                    if ( $subscription->recurring_amount != $subscription->initial_amount ) {
73
                        printf(
74
                            _x( '%s then %s', 'Initial subscription amount then billing cycle and amount', 'invoicing' ),
75
                            $initial,
76
                            $billing
77
                        );
78
                    } else {
79
                        echo $billing;
80
                    }
81
82
                ?>
83
            </p>
84
85
            <p class="wpi-meta-row wpi-billed-times">
86
                <label><?php _e( 'Times Billed:', 'invoicing' ); ?></label>
87
                <?php echo $subscription->get_times_billed() . ' / ' . ( ( $subscription->bill_times == 0 ) ? 'Until Cancelled' : $subscription->bill_times ); ?>
88
            </p>
89
90
            <p class="wpi-meta-row wpi-start-date">
91
                <label><?php _e( 'Start Date:', 'invoicing' ); ?></label>
92
                <?php echo date_i18n( get_option( 'date_format' ), strtotime( $subscription->created, current_time( 'timestamp' ) ) ); ?>
0 ignored issues
show
Bug introduced by
It seems like get_option('date_format') can also be of type false; however, parameter $format of date_i18n() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

92
                <?php echo date_i18n( /** @scrutinizer ignore-type */ get_option( 'date_format' ), strtotime( $subscription->created, current_time( 'timestamp' ) ) ); ?>
Loading history...
93
            </p>
94
95
            <p class="wpi-meta-row wpi-end-date">
96
                <label><?php echo $exipired ? __( 'Expired On:', 'invoicing' ) : __( 'Renews On:', 'invoicing' ); ?></label>
97
                <?php echo date_i18n( get_option( 'date_format' ), strtotime( $subscription->expiration, current_time( 'timestamp' ) ) ); ?>
98
            </p>
99
100
            <?php if ( $subscription->status ) { ?>
101
                <p class="wpi-meta-row wpi-sub-status">
102
                    <label><?php _e( 'Subscription Status:', 'invoicing'); ?> </label><?php echo $subscription->get_status_label(); ?>
103
                </p>
104
            <?php } ?>
105
106
            <?php if ( $invoice->is_renewal() ) { ?>
107
                <p class="wpi-meta-row wpi-invoice-parent">
108
                    <label><?php _e( 'Parent Invoice:', 'invoicing'); ?></label>
109
                    <?php
110
                        $parent = $invoice->get_parent_payment();
111
112
                        if ( $parent->get_id() ) {
113
                            $parent_url = esc_url( get_edit_post_link( $parent->get_id() ) );
114
                            $parent_id  = $parent->get_number();
115
                            echo "<a href='$parent_url'>$parent_id</a>";
116
                        } else {
117
                            echo '<del>' . __( 'Deleted', 'invoicing' ) . '</del>';
118
                        }
119
                    ?>
120
121
                </p>
122
            <?php } ?>
123
124
        <?php
125
126
    }
127
128
}
129