Conditions | 6 |
Paths | 16 |
Total Lines | 79 |
Code Lines | 48 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 1 | Features | 1 |
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 |
||
49 | public function getData() |
||
50 | { |
||
51 | $this->validate('merchantId', 'merchantPassword', 'acquirerId', 'transactionId', 'amount', 'currency', 'card'); |
||
52 | |||
53 | // Check for AVS and require billingAddress1 and billingPostcode |
||
54 | if ( $this->getRequireAvsCheck() ) |
||
55 | { |
||
56 | $this->getCard()->validate('billingAddress1', 'billingPostcode'); |
||
57 | } |
||
58 | |||
59 | // Tokenized cards require the CVV and nothing else, token replaces the card number |
||
60 | if ( $this->getCardReference() ) |
||
61 | { |
||
62 | $this->validate('cardReference'); |
||
63 | $this->getCard()->validate('cvv', 'expiryMonth', 'expiryYear'); |
||
64 | |||
65 | $cardDetails = [ |
||
66 | 'CardCVV2' => $this->getCard()->getCvv(), |
||
67 | 'CardExpiryDate' => $this->getCard()->getExpiryDate('my'), |
||
68 | 'CardNumber' => $this->getCardReference() |
||
69 | ]; |
||
70 | } |
||
71 | else |
||
72 | { |
||
73 | $this->getCard()->validate(); |
||
74 | |||
75 | $cardDetails = [ |
||
76 | 'CardCVV2' => $this->getCard()->getCvv(), |
||
77 | 'CardExpiryDate' => $this->getCard()->getExpiryDate('my'), |
||
78 | 'CardNumber' => $this->getCard()->getNumber(), |
||
79 | 'IssueNumber' => $this->getCard()->getIssueNumber() |
||
80 | ]; |
||
81 | } |
||
82 | |||
83 | // Only pass the StartDate if year/month are set otherwise it returns 1299 |
||
84 | if ( $this->getCard()->getStartYear() && $this->getCard()->getStartMonth() ) |
||
85 | { |
||
86 | $cardDetails['StartDate'] = $this->getCard()->getStartDate('my'); |
||
87 | } |
||
88 | |||
89 | $transactionDetails = [ |
||
90 | 'AcquirerId' => $this->getAcquirerId(), |
||
91 | 'Amount' => $this->formatAmount(), |
||
92 | 'Currency' => $this->getCurrencyNumeric(), |
||
93 | 'CurrencyExponent' => $this->getCurrencyDecimalPlaces(), |
||
94 | 'IPAddress' => $this->getClientIp(), |
||
95 | 'MerchantId' => $this->getMerchantId(), |
||
96 | 'OrderNumber' => $this->getTransactionId(), |
||
97 | 'Signature' => $this->generateSignature(), |
||
98 | 'SignatureMethod' => 'SHA1', |
||
99 | 'TransactionCode' => $this->getTransactionCode() |
||
100 | ]; |
||
101 | |||
102 | $billingDetails = [ |
||
103 | 'BillToAddress' => $this->getCard()->getAddress1(), |
||
104 | 'BillToZipPostCode' => $this->formatPostcode(), |
||
105 | 'BillToFirstName' => $this->getCard()->getFirstName(), |
||
106 | 'BillToLastName' => $this->getCard()->getLastName(), |
||
107 | 'BillToCity' => $this->getCard()->getCity(), |
||
108 | 'BillToCountry' => $this->formatCountry(), |
||
109 | 'BillToEmail' => $this->getCard()->getEmail(), |
||
110 | 'BillToTelephone' => $this->getCard()->getPhone(), |
||
111 | 'BillToFax' => $this->getCard()->getFax() |
||
112 | ]; |
||
113 | |||
114 | // FAC only accepts two digit state abbreviations from the USA |
||
115 | if ( $billingDetails['BillToCountry'] == 840 ) |
||
116 | { |
||
117 | $billingDetails['BillToState'] = $this->formatState(); |
||
118 | } |
||
119 | |||
120 | $data = [ |
||
121 | 'TransactionDetails' => $transactionDetails, |
||
122 | 'CardDetails' => $cardDetails, |
||
123 | 'BillingDetails' => $billingDetails |
||
124 | ]; |
||
125 | |||
126 | return $data; |
||
127 | } |
||
128 | |||
232 |