Conditions | 6 |
Paths | 8 |
Total Lines | 77 |
Code Lines | 54 |
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 |
||
17 | public function collectRates(Mage_Shipping_Model_Rate_Request $request) |
||
18 | { |
||
19 | Varien_Profiler::start($this->_name . '_collect_rate'); |
||
20 | |||
21 | if (!$this->getType()) { |
||
22 | Mage::helper($this->_name)->addLog('Calc -> no code'); |
||
23 | Varien_Profiler::stop($this->_name . '_collect_rate'); |
||
24 | return false; |
||
25 | } |
||
26 | $type = $this->getType(); |
||
27 | |||
28 | $valid = $this->validateRequest($request); |
||
29 | if ($valid !== true) { |
||
30 | return $valid; |
||
31 | } |
||
32 | |||
33 | $city = mb_convert_case(trim($request->getDestCity()), MB_CASE_TITLE, "UTF-8"); |
||
34 | |||
35 | if ($this->getConfig('onlyone')) { |
||
36 | Mage::helper($this->_name)->addLog('Calc -> only one standart item'); |
||
37 | $weight = round($this->getConfig('oneweight') * 1000 / $this->getConfig('weightunit'), 3); |
||
38 | $dimensions = Mage::helper($this->_name)->getStandardSizes(); |
||
39 | } else { |
||
40 | $quote = $this->getQuote(); |
||
41 | $cartItems = $quote->getAllVisibleItems(); |
||
42 | |||
43 | Mage::helper($this->_name)->addLog('Found ' . count($cartItems) . ' items in quote'); |
||
44 | Mage::helper($this->_name)->addLog('Calc -> every item in cart'); |
||
45 | |||
46 | $processed_dimensions = Mage::helper($this->_name)->getSizes($cartItems, true); |
||
47 | $weight = $processed_dimensions['weight']; |
||
48 | |||
49 | $dimensions = Mage::helper($this->_name)->dimenAlgo($processed_dimensions['dimensions']); |
||
50 | } |
||
51 | |||
52 | $data = [ |
||
53 | 'client_id' => $this->getConfig('client_id'), |
||
54 | 'sender_id' => $this->getConfig('sender'), |
||
55 | 'city_from' => $this->getConfig('homecity'), |
||
56 | 'city_to' => $city, |
||
57 | 'weight' => $weight, |
||
58 | 'total_cost' => $request->getPackageValue(), |
||
59 | 'order_cost' => $request->getPackageValue(), |
||
60 | 'payment_method' => $this->getConfig('payment_type'), |
||
61 | 'height' => $dimensions['C'], |
||
62 | 'width' => $dimensions['B'], |
||
63 | 'length' => $dimensions['A'], |
||
64 | 'to_yd_warehouse' => $this->getConfig('yd_warehouse'), |
||
65 | 'assessed_value' => $request->getPackageValue(), |
||
66 | 'index_city' => $request->getDestPostcode(), |
||
67 | 'delivery_type' => $type |
||
68 | ]; |
||
69 | |||
70 | $result = Mage::getModel('shipping/rate_result'); |
||
71 | |||
72 | Mage::helper('yandexdelivery')->__('Will calc type -> ' . $type); |
||
73 | |||
74 | Varien_Profiler::start($this->_name . '_request'); |
||
75 | $response = Mage::getModel($this->_name . '/carrier')->searchDeliveryList($data); |
||
76 | Varien_Profiler::stop($this->_name . '_request'); |
||
77 | |||
78 | if ($response->status != "ok") { |
||
79 | $errors = (array) $response->data->errors; |
||
80 | $error_text = Mage::helper('yandexdelivery')->__('Error:') . ' '; |
||
81 | foreach ($errors as $key => $value) { |
||
82 | $error_text .= $key . " — " . $value . "\n"; |
||
83 | } |
||
84 | return $this->returnError($error_text); |
||
85 | } |
||
86 | |||
87 | $this->processType($response, $type, $request, $result); |
||
88 | |||
89 | Mage::helper($this->_name)->addLog('Calculating ended'); |
||
90 | |||
91 | Varien_Profiler::stop($this->_name . '_collect_rate'); |
||
92 | return $result; |
||
93 | } |
||
94 | |||
219 |
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.