Conditions | 7 |
Paths | 36 |
Total Lines | 56 |
Code Lines | 38 |
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 |
||
61 | private function initSession($order, $enc_key, $itemid) |
||
62 | { |
||
63 | $paytype = Mage::getStoreConfig('payment/payture/paytype'); |
||
64 | $request = array( |
||
65 | 'SessionType' => $paytype, |
||
66 | 'OrderId' => $order->getId(), |
||
67 | 'Amount' => $order->getGrandTotal() * 100, |
||
68 | 'Total' => $order->getGrandTotal(), |
||
69 | 'IP' => $order->getRemoteIp(), |
||
70 | 'Url' => Mage::getUrl( |
||
71 | 'payture/payment/result/', |
||
72 | array('_secure' => true, 'order' => $enc_key) |
||
73 | ) |
||
74 | ); |
||
75 | // @codingStandardsIgnoreStart |
||
76 | if (Mage::getStoreConfig('payment/payture/taxenable')) { |
||
77 | $request['Cheque'] = base64_encode(Mage::helper('payture')->getOrderItemsJson($order)); |
||
78 | Mage::helper('payture')->addLog('Cheque base64_json_decode: ' . print_r(Mage::helper('core')->jsonDecode(base64_decode($request['Cheque'])),1)); |
||
79 | } |
||
80 | // @codingStandardsIgnoreEnd |
||
81 | |||
82 | //add product names |
||
83 | $products = ''; |
||
84 | $items = $order->getItemsCollection(); |
||
85 | foreach ($items as $item) { |
||
86 | if ($item->getOriginalPrice() > 0) { |
||
87 | $products .= $item->getName() . ', '; |
||
88 | } |
||
89 | } |
||
90 | |||
91 | if (substr($products, strlen($products) - 2, 2) == ', ') { |
||
92 | $products = substr($products, 0, strlen($products) - 2); |
||
93 | } |
||
94 | |||
95 | $request['Product'] = $products; |
||
96 | |||
97 | $result = $this->requestApiPost(Mage::helper('payture')->getHost() . 'Init', $request); |
||
98 | Mage::helper('payture')->addLog($result); |
||
99 | $xml = simplexml_load_string($result); |
||
100 | |||
101 | if ((bool) $xml["Success"][0] == true) { |
||
|
|||
102 | if ($xml["SessionId"][0]) { |
||
103 | $item = Mage::getModel('payture/keys')->load($itemid); |
||
104 | $item->setSessionid($xml["SessionId"][0]); |
||
105 | $item->setPaytype($paytype); |
||
106 | $item->setState('New'); |
||
107 | $item->setDate(Mage::getModel('core/date')->date('Y-m-d H:i:s')); |
||
108 | $item->save(); |
||
109 | return $xml["SessionId"][0]; |
||
110 | } |
||
111 | } else { |
||
112 | $session = Mage::getSingleton('checkout/session'); |
||
113 | $session->addError($xml["ErrCode"][0]); |
||
114 | return false; |
||
115 | } |
||
116 | } |
||
117 | |||
166 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.