Conditions | 3 |
Paths | 3 |
Total Lines | 84 |
Code Lines | 58 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
41 | function print_result() |
||
42 | { |
||
43 | global $pxpay; |
||
44 | |||
45 | $enc_hex = $_REQUEST["result"]; |
||
46 | #getResponse method in PxPay object returns PxPayResponse object |
||
47 | #which encapsulates all the response data |
||
48 | $rsp = $pxpay->getResponse($enc_hex); |
||
49 | |||
50 | |||
51 | # the following are the fields available in the PxPayResponse object |
||
52 | $Success = $rsp->getSuccess(); # =1 when request succeeds |
||
53 | $AmountSettlement = $rsp->getAmountSettlement(); |
||
54 | $AuthCode = $rsp->getAuthCode(); # from bank |
||
55 | $CardName = $rsp->getCardName(); # e.g. "Visa" |
||
56 | $CardNumber = $rsp->getCardNumber(); # Truncated card number |
||
57 | $DateExpiry = $rsp->getDateExpiry(); # in mmyy format |
||
58 | $DpsBillingId = $rsp->getDpsBillingId(); |
||
59 | $BillingId = $rsp->getBillingId(); |
||
60 | $CardHolderName = $rsp->getCardHolderName(); |
||
61 | $DpsTxnRef = $rsp->getDpsTxnRef(); |
||
62 | $TxnType = $rsp->getTxnType(); |
||
63 | $TxnData1 = $rsp->getTxnData1(); |
||
64 | $TxnData2 = $rsp->getTxnData2(); |
||
65 | $TxnData3 = $rsp->getTxnData3(); |
||
66 | $CurrencySettlement= $rsp->getCurrencySettlement(); |
||
67 | $ClientInfo = $rsp->getClientInfo(); # The IP address of the user who submitted the transaction |
||
68 | $TxnId = $rsp->getTxnId(); |
||
69 | $CurrencyInput = $rsp->getCurrencyInput(); |
||
70 | $EmailAddress = $rsp->getEmailAddress(); |
||
71 | $MerchantReference = $rsp->getMerchantReference(); |
||
72 | $ResponseText = $rsp->getResponseText(); |
||
73 | $TxnMac = $rsp->getTxnMac(); # An indication as to the uniqueness of a card used in relation to others |
||
74 | |||
75 | if ($rsp->getSuccess() == "1") { |
||
76 | $result = "The transaction was approved."; |
||
77 | |||
78 | # Sending invoices/updating order status within database etc. |
||
79 | |||
80 | if (!isProcessed($TxnId)) { |
||
81 | # Send emails, generate invoices, update order status etc. |
||
82 | } |
||
83 | } else { |
||
84 | $result = "The transaction was declined."; |
||
85 | } |
||
86 | |||
87 | print <<<HTMLEOF |
||
88 | <html> |
||
89 | <head> |
||
90 | <title>Payment Express PxPay transaction result</title> |
||
91 | </head> |
||
92 | <body> |
||
93 | <h1>Payment Express PxPay transaction result</h1> |
||
94 | <p>$result</p> |
||
95 | <table border=1> |
||
96 | <tr><th>Name</th> <th>Value</th> </tr> |
||
97 | <tr><td>Success</td> <td>$Success</td></tr> |
||
98 | <tr><td>TxnType</td> <td>$TxnType</td></tr> |
||
99 | <tr><td>CurrencyInput</td> <td>$CurrencyInput</td></tr> |
||
100 | <tr><td>MerchantReference</td> <td>$MerchantReference</td></tr> |
||
101 | <tr><td>TxnData1</td> <td>$TxnData1</td></tr> |
||
102 | <tr><td>TxnData2</td> <td>$TxnData2</td></tr> |
||
103 | <tr><td>TxnData3</td> <td>$TxnData3</td></tr> |
||
104 | <tr><td>AuthCode</td> <td>$AuthCode</td></tr> |
||
105 | <tr><td>CardName</td> <td>$CardName</td></tr> |
||
106 | <tr><td>CardHolderName</td> <td>$CardHolderName</td></tr> |
||
107 | <tr><td>CardNumber</td> <td>$CardNumber</td></tr> |
||
108 | <tr><td>DateExpiry</td> <td>$DateExpiry</td></tr> |
||
109 | <tr><td>CardHolderName</td> <td>$CardHolderName</td></tr> |
||
110 | <tr><td>ClientInfo</td> <td>$ClientInfo</td></tr> |
||
111 | <tr><td>TxnId</td> <td>$TxnId</td></tr> |
||
112 | <tr><td>EmailAddress</td> <td>$EmailAddress</td></tr> |
||
113 | <tr><td>DpsTxnRef</td> <td>$DpsTxnRef</td></tr> |
||
114 | <tr><td>BillingId</td> <td>$BillingId</td></tr> |
||
115 | <tr><td>DpsBillingId</td> <td>$DpsBillingId</td></tr> |
||
116 | <tr><td>AmountSettlement</td> <td>$AmountSettlement</td></tr> |
||
117 | <tr><td>CurrencySettlement</td> <td>$CurrencySettlement</td></tr> |
||
118 | <tr><td>TxnMac</td> <td>$TxnMac</td></tr> |
||
119 | <tr><td>ResponseText</td> <td>$ResponseText</td></tr> |
||
120 | </table> |
||
121 | </body> |
||
122 | </html> |
||
123 | HTMLEOF; |
||
124 | } |
||
125 | |||
255 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.