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