Completed
Pull Request — 23 (#431)
by Harald
10:27
created

TransactionSearch   F

Complexity

Total Complexity 63

Size/Duplication

Total Lines 126
Duplicated Lines 14.29 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
dl 18
loc 126
rs 3.6585
c 0
b 0
f 0
wmc 63
lcom 0
cbo 6

63 Methods

Rating   Name   Duplication   Size   Complexity  
A amount() 0 1 1
A authorizationExpiredAt() 0 1 1
A authorizedAt() 0 1 1
A billingCompany() 0 1 1
A billingCountryName() 0 1 1
A billingExtendedAddress() 0 1 1
A billingFirstName() 0 1 1
A billingLastName() 0 1 1
A billingLocality() 0 1 1
A billingPostalCode() 0 1 1
A billingRegion() 0 1 1
A billingStreetAddress() 0 1 1
A createdAt() 0 1 1
A creditCardCardholderName() 0 1 1
A creditCardExpirationDate() 0 1 1
A creditCardNumber() 0 1 1
A creditCardUniqueIdentifier() 0 1 1
A currency() 0 1 1
A customerCompany() 0 1 1
A customerEmail() 0 1 1
A customerFax() 0 1 1
A customerFirstName() 0 1 1
A customerId() 0 1 1
A customerLastName() 0 1 1
A customerPhone() 0 1 1
A customerWebsite() 0 1 1
A disbursementDate() 0 1 1
A disputeDate() 0 1 1
A europeBankAccountIban() 0 1 1
A failedAt() 0 1 1
A gatewayRejectedAt() 0 1 1
A id() 0 1 1
A ids() 0 1 1
A merchantAccountId() 0 1 1
A orderId() 0 1 1
A paymentInstrumentType() 0 1 1
A paymentMethodToken() 0 1 1
A paypalAuthorizationId() 0 1 1
A paypalPayerEmail() 0 1 1
A paypalPaymentId() 0 1 1
A processorAuthorizationCode() 0 1 1
A processorDeclinedAt() 0 1 1
A refund() 0 1 1
A settledAt() 0 1 1
A settlementBatchId() 0 1 1
A shippingCompany() 0 1 1
A shippingCountryName() 0 1 1
A shippingExtendedAddress() 0 1 1
A shippingFirstName() 0 1 1
A shippingLastName() 0 1 1
A shippingLocality() 0 1 1
A shippingPostalCode() 0 1 1
A shippingRegion() 0 1 1
A shippingStreetAddress() 0 1 1
A submittedForSettlementAt() 0 1 1
A user() 0 1 1
A voidedAt() 0 1 1
A createdUsing() 0 7 1
A creditCardCardType() 18 18 1
A creditCardCustomerLocation() 0 7 1
A source() 0 4 1
A status() 0 17 1
A type() 0 7 1

How to fix   Duplicated Code    Complexity   

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:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like TransactionSearch often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use TransactionSearch, and based on these observations, apply Extract Interface, too.

1
<?php
2
namespace Braintree;
3
4
class TransactionSearch
5
{
6
    public static function amount()                     { return new RangeNode("amount"); }
7
    public static function authorizationExpiredAt()     { return new RangeNode("authorizationExpiredAt"); }
8
    public static function authorizedAt()               { return new RangeNode("authorizedAt"); }
9
    public static function billingCompany()             { return new TextNode('billing_company'); }
10
    public static function billingCountryName()         { return new TextNode('billing_country_name'); }
11
    public static function billingExtendedAddress()     { return new TextNode('billing_extended_address'); }
12
    public static function billingFirstName()           { return new TextNode('billing_first_name'); }
13
    public static function billingLastName()            { return new TextNode('billing_last_name'); }
14
    public static function billingLocality()            { return new TextNode('billing_locality'); }
15
    public static function billingPostalCode()          { return new TextNode('billing_postal_code'); }
16
    public static function billingRegion()              { return new TextNode('billing_region'); }
17
    public static function billingStreetAddress()       { return new TextNode('billing_street_address'); }
18
    public static function createdAt()                  { return new RangeNode("createdAt"); }
19
    public static function creditCardCardholderName()   { return new TextNode('credit_card_cardholderName'); }
20
    public static function creditCardExpirationDate()   { return new EqualityNode('credit_card_expiration_date'); }
21
    public static function creditCardNumber()           { return new PartialMatchNode('credit_card_number'); }
22
    public static function creditCardUniqueIdentifier() { return new TextNode('credit_card_unique_identifier'); }
23
    public static function currency()                   { return new TextNode('currency'); }
24
    public static function customerCompany()            { return new TextNode('customer_company'); }
25
    public static function customerEmail()              { return new TextNode('customer_email'); }
26
    public static function customerFax()                { return new TextNode('customer_fax'); }
27
    public static function customerFirstName()          { return new TextNode('customer_first_name'); }
28
    public static function customerId()                 { return new TextNode('customer_id'); }
29
    public static function customerLastName()           { return new TextNode('customer_last_name'); }
30
    public static function customerPhone()              { return new TextNode('customer_phone'); }
31
    public static function customerWebsite()            { return new TextNode('customer_website'); }
32
    public static function disbursementDate()           { return new RangeNode("disbursementDate"); }
33
    public static function disputeDate()                { return new RangeNode("disputeDate"); }
34
    public static function europeBankAccountIban()      { return new TextNode("europeBankAccountIban"); }
35
    public static function failedAt()                   { return new RangeNode("failedAt"); }
36
    public static function gatewayRejectedAt()          { return new RangeNode("gatewayRejectedAt"); }
37
    public static function id()                         { return new TextNode('id'); }
38
    public static function ids()                        { return new MultipleValueNode('ids'); }
39
    public static function merchantAccountId()          { return new MultipleValueNode("merchant_account_id"); }
40
    public static function orderId()                    { return new TextNode('order_id'); }
41
    public static function paymentInstrumentType()      { return new MultipleValueNode('paymentInstrumentType'); }
42
    public static function paymentMethodToken()         { return new TextNode('payment_method_token'); }
43
    public static function paypalAuthorizationId()      { return new TextNode('paypal_authorization_id'); }
44
    public static function paypalPayerEmail()           { return new TextNode('paypal_payer_email'); }
45
    public static function paypalPaymentId()            { return new TextNode('paypal_payment_id'); }
46
    public static function processorAuthorizationCode() { return new TextNode('processor_authorization_code'); }
47
    public static function processorDeclinedAt()        { return new RangeNode("processorDeclinedAt"); }
48
    public static function refund()                     { return new KeyValueNode("refund"); }
49
    public static function settledAt()                  { return new RangeNode("settledAt"); }
50
    public static function settlementBatchId()          { return new TextNode('settlement_batch_id'); }
51
    public static function shippingCompany()            { return new TextNode('shipping_company'); }
52
    public static function shippingCountryName()        { return new TextNode('shipping_country_name'); }
53
    public static function shippingExtendedAddress()    { return new TextNode('shipping_extended_address'); }
54
    public static function shippingFirstName()          { return new TextNode('shipping_first_name'); }
55
    public static function shippingLastName()           { return new TextNode('shipping_last_name'); }
56
    public static function shippingLocality()           { return new TextNode('shipping_locality'); }
57
    public static function shippingPostalCode()         { return new TextNode('shipping_postal_code'); }
58
    public static function shippingRegion()             { return new TextNode('shipping_region'); }
59
    public static function shippingStreetAddress()      { return new TextNode('shipping_street_address'); }
60
    public static function submittedForSettlementAt()   { return new RangeNode("submittedForSettlementAt"); }
61
    public static function user()                       { return new MultipleValueNode('user'); }
62
    public static function voidedAt()                   { return new RangeNode("voidedAt"); }
63
64
    public static function createdUsing()
65
    {
66
        return new MultipleValueNode('created_using', [
67
            Transaction::FULL_INFORMATION,
68
            Transaction::TOKEN
69
        ]);
70
    }
71
72 View Code Duplication
    public static function creditCardCardType()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
73
    {
74
        return new MultipleValueNode('credit_card_card_type', [
75
            CreditCard::AMEX,
76
            CreditCard::CARTE_BLANCHE,
77
            CreditCard::CHINA_UNION_PAY,
78
            CreditCard::DINERS_CLUB_INTERNATIONAL,
79
            CreditCard::DISCOVER,
80
            CreditCard::JCB,
81
            CreditCard::LASER,
82
            CreditCard::MAESTRO,
83
            CreditCard::MASTER_CARD,
84
            CreditCard::SOLO,
85
            CreditCard::SWITCH_TYPE,
86
            CreditCard::VISA,
87
            CreditCard::UNKNOWN
88
        ]);
89
    }
90
91
    public static function creditCardCustomerLocation()
92
    {
93
        return new MultipleValueNode('credit_card_customer_location', [
94
            CreditCard::INTERNATIONAL,
95
            CreditCard::US
96
        ]);
97
    }
98
99
    public static function source()
100
    {
101
        return new MultipleValueNode('source', []);
102
    }
103
104
    public static function status()
105
    {
106
        return new MultipleValueNode('status', [
107
            Transaction::AUTHORIZATION_EXPIRED,
108
            Transaction::AUTHORIZING,
109
            Transaction::AUTHORIZED,
110
            Transaction::GATEWAY_REJECTED,
111
            Transaction::FAILED,
112
            Transaction::PROCESSOR_DECLINED,
113
            Transaction::SETTLED,
114
            Transaction::SETTLING,
115
            Transaction::SUBMITTED_FOR_SETTLEMENT,
116
            Transaction::VOIDED,
117
            Transaction::SETTLEMENT_DECLINED,
118
            Transaction::SETTLEMENT_PENDING
119
        ]);
120
    }
121
122
    public static function type()
123
    {
124
        return new MultipleValueNode('type', [
125
            Transaction::SALE,
126
            Transaction::CREDIT
127
        ]);
128
    }
129
}
130
class_alias('Braintree\TransactionSearch', 'Braintree_TransactionSearch');
131