Conditions | 11 |
Paths | 12 |
Total Lines | 55 |
Code Lines | 31 |
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 |
||
60 | public function writeItem(array $item) |
||
61 | { |
||
62 | $customer = clone $this->customerModel; |
||
63 | |||
64 | //get address |
||
65 | $addresses = []; |
||
66 | if (isset($item['address'])) { |
||
67 | $addresses = $item['address']; |
||
68 | unset($item['address']); |
||
69 | } |
||
70 | |||
71 | $customer->setData($item); |
||
72 | |||
73 | //if we are adding addresses - create |
||
74 | //model for each and set it on the customer |
||
75 | if ($this->addressModel) { |
||
76 | foreach ($addresses as $addressData) { |
||
77 | //lookup region info: |
||
78 | $name = ''; |
||
79 | if (isset($addressData['firstname']) && $addressData['lastname']) { |
||
80 | $name = $addressData['firstname'] . " " . $addressData['lastname']; |
||
81 | } |
||
82 | |||
83 | $regionId = false; |
||
84 | if (isset($addressData['region']) && $addressData['country_id']) { |
||
85 | $regionId = $this->lookUpRegion($addressData['region'], $addressData['country_id'], $name); |
||
86 | } |
||
87 | |||
88 | if ($regionId) { |
||
89 | $addressData['region_id'] = $regionId; |
||
90 | unset($addressData['region']); |
||
91 | } |
||
92 | |||
93 | $address = clone $this->addressModel; |
||
94 | |||
95 | $address->setData($addressData); |
||
96 | $address->setIsDefaultShipping(true); |
||
97 | $address->setIsDefaultBilling(true); |
||
98 | $customer->addAddress($address); |
||
99 | } |
||
100 | } |
||
101 | |||
102 | try { |
||
103 | $customer->save(); |
||
104 | } catch (\Mage_Core_Exception $e) { |
||
105 | $message = $e->getMessage(); |
||
106 | if (isset($item['email'])) { |
||
107 | $message .= " : " . $item['email']; |
||
108 | } |
||
109 | |||
110 | throw new MagentoSaveException($message); |
||
111 | } |
||
112 | |||
113 | return $this; |
||
114 | } |
||
115 | |||
158 |