| Conditions | 6 |
| Paths | 8 |
| Total Lines | 57 |
| 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 |
||
| 14 | public function sendAction() |
||
| 15 | { |
||
| 16 | |||
| 17 | if (!$this->getRequest()->isPost()) { |
||
| 18 | Mage::getSingleton('adminhtml/session')->addError('Sending error'); |
||
| 19 | return $this->_redirectReferer(); |
||
| 20 | } |
||
| 21 | |||
| 22 | $keys = ['orderid', 'type', 'warehouse', 'sender', 'requisite', 'date', 'street', 'house']; |
||
| 23 | |||
| 24 | foreach ($keys as $key) { |
||
| 25 | $tmp = Mage::app()->getRequest()->getParam($key); |
||
| 26 | if (!$tmp) { |
||
| 27 | $return = 'No ' . $key . ' in POST'; |
||
| 28 | return $this->getResponse()->setBody($return); |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | $result = Mage::getModel('yandexdelivery/carrier')->createOrder( |
||
| 33 | Mage::app()->getRequest()->getParam('orderid'), |
||
| 34 | Mage::app()->getRequest()->getParam('warehouse'), |
||
| 35 | Mage::app()->getRequest()->getParam('sender'), |
||
| 36 | Mage::app()->getRequest()->getParam('requisite'), |
||
| 37 | Mage::app()->getRequest()->getParam('date'), |
||
| 38 | Mage::app()->getRequest()->getParam('street'), |
||
| 39 | Mage::app()->getRequest()->getParam('house') |
||
| 40 | ); |
||
| 41 | |||
| 42 | if ($result->status == "ok") { |
||
| 43 | Mage::getSingleton('adminhtml/session')->addSuccess( |
||
| 44 | Mage::helper('yandexdelivery')->__('Order template has been successfully created') |
||
| 45 | ); |
||
| 46 | |||
| 47 | $shipment = Mage::getModel('yandexdelivery/shipment'); |
||
| 48 | |||
| 49 | $data = [ |
||
| 50 | 'yd_id' => $result->data->order->id, |
||
| 51 | 'order_id' => Mage::app()->getRequest()->getParam('orderid'), |
||
| 52 | 'sender_id' => Mage::app()->getRequest()->getParam('sender'), |
||
| 53 | 'requisite_id' => Mage::app()->getRequest()->getParam('requisite'), |
||
| 54 | 'warehouse_id' => Mage::app()->getRequest()->getParam('warehouse'), |
||
| 55 | 'type' => Mage::app()->getRequest()->getParam('type') |
||
| 56 | ]; |
||
| 57 | $shipment->setData($data); |
||
| 58 | $shipment->save(); |
||
| 59 | |||
| 60 | //will auto-approve sended earlier order template |
||
| 61 | $this->confirmOrder($result->data->order->id, Mage::app()->getRequest()->getParam('sender'), Mage::app()->getRequest()->getParam('type')); |
||
| 62 | return $this->_redirectReferer(); |
||
| 63 | } |
||
| 64 | $msg = ''; |
||
| 65 | foreach ($result->data->errors as $error) { |
||
| 66 | $msg .= $error . '. '; |
||
| 67 | } |
||
| 68 | Mage::getSingleton('adminhtml/session')->addError($msg); |
||
| 69 | $this->_redirectReferer(); |
||
| 70 | } |
||
| 71 | |||
| 185 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.