Completed
Branch FET-10486-add-timestamp-checki... (611b15)
by
unknown
105:07 queued 90:18
created

GatewayDataFormatter   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 120
Duplicated Lines 21.67 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 26
loc 120
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 2

6 Methods

Rating   Name   Duplication   Size   Complexity  
A formatPartialPaymentLineItemName() 0 9 1
A formatPartialPaymentLineItemDesc() 13 13 1
A formatLineItemName() 0 14 1
A formatLineItemDesc() 0 10 1
A formatOrderDescription() 13 13 1
A formatCurrency() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace EventEspresso\core\services\payment_methods\gateways;
3
4
defined('EVENT_ESPRESSO_VERSION') || exit;
5
6
7
8
/**
9
 * Class GatewayDataFormatter
10
 * Helper for gateway classes which helps to prepare data for sending to gateways. These methods help
11
 * to keep data sent to the various gateways consistent and filterable.
12
 *
13
 * @package        Event Espresso
14
 * @author         Mike Nelson
15
 * @since          4.9.31.p
16
 */
17
class GatewayDataFormatter implements GatewayDataFormatterInterface
18
{
19
20
    /**
21
     * Gets the text to use for a gateway's line item name when this is a partial payment
22
     *
23
     * @param \EEI_Payment $payment
24
     * @return string
25
     */
26
    public function formatPartialPaymentLineItemName(\EEI_Payment $payment)
27
    {
28
        return apply_filters(
29
            'EEG_Paypal_Pro__do_direct_payment__partial_amount_line_item_name',
30
            $payment->get_first_event_name(),
31
            $this,
32
            $payment
33
        );
34
    }
35
36
37
38
    /**
39
     * Gets the text to use for a gateway's line item description when this is a partial payment
40
     *
41
     * @param \EEI_Payment $payment
42
     * @return string
43
     */
44 View Code Duplication
    public function formatPartialPaymentLineItemDesc(\EEI_Payment $payment)
45
    {
46
        return apply_filters(
47
            'FHEE__EE_Gateway___partial_payment_desc',
48
            sprintf(
49
                __("Payment of %s for %s", "event_espresso"),
50
                $payment->get_pretty('PAY_amount', 'no_currency_code'),
51
                $payment->get_first_event_name()
52
            ),
53
            $this,
54
            $payment
55
        );
56
    }
57
58
59
60
    /**
61
     * Gets the name to use for a line item when sending line items to the gateway
62
     *
63
     * @param \EEI_Line_Item $line_item
64
     * @param \EEI_Payment   $payment
65
     * @return string
66
     */
67
    public function formatLineItemName(\EEI_Line_Item $line_item, \EEI_Payment $payment)
68
    {
69
        return apply_filters(
70
            'FHEE__EE_gateway___line_item_name',
71
            sprintf(
72
                _x('%1$s for %2$s', 'Ticket for Event', 'event_espresso'),
73
                $line_item->name(),
74
                $line_item->ticket_event_name()
75
            ),
76
            $this,
77
            $line_item,
78
            $payment
79
        );
80
    }
81
82
83
84
    /**
85
     * Gets the description to use for a line item when sending line items to the gateway
86
     *
87
     * @param \EEI_Line_Item $line_item
88
     * @param \EEI_Payment   $payment
89
     * @return string
90
     */
91
    public function formatLineItemDesc(\EEI_Line_Item $line_item, \EEI_Payment $payment)
92
    {
93
        return apply_filters(
94
            'FHEE__EE_Gateway___line_item_desc',
95
            $line_item->desc(),
96
            $this,
97
            $line_item,
98
            $payment
99
        );
100
    }
101
102
103
104
    /**
105
     * Gets the order description that should generally be sent to gateways
106
     *
107
     * @param \EEI_Payment $payment
108
     * @return string
109
     */
110 View Code Duplication
    public function formatOrderDescription(\EEI_Payment $payment)
111
    {
112
        return apply_filters(
113
            'FHEE__EE_Gateway___order_description',
114
            sprintf(
115
                __('Event Registrations from %1$s for %2$s', "event_espresso"),
116
                get_bloginfo('name'),
117
                $payment->get_first_event_name()
118
            ),
119
            $this,
120
            $payment
121
        );
122
    }
123
124
125
126
    /**
127
     * Formats the amount so it can generally be sent to gateways
128
     *
129
     * @param float $amount
130
     * @return string
131
     */
132
    public function formatCurrency($amount)
133
    {
134
        return number_format($amount, 2, '.', '');
135
    }
136
}
137
// End of file GatewayDataFormatter.php
138
// Location: core\services\gateways/GatewayDataFormatter.php