Conditions | 2 |
Paths | 2 |
Total Lines | 90 |
Code Lines | 61 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
151 | private function getUpsRateValue(array $configuration, array $packageValues) |
||
152 | { |
||
153 | $rate = new Rate( |
||
154 | $configuration['accesskey'], |
||
155 | $configuration['username'], |
||
156 | $configuration['password'] |
||
157 | ); |
||
158 | |||
159 | $packageValues['account'] = $configuration['account']; |
||
160 | $packageValues['origination_postcode'] = $configuration['origination_postcode']; |
||
161 | $packageValues['origination_country_code'] = $configuration['origination_country_code']; |
||
162 | $packageValues['origination_address'] = $configuration['origination_address']; |
||
163 | $packageValues['origination_city'] = $configuration['origination_city']; |
||
164 | $packageValues['service_code'] = $this->getServiceCode($packageValues['origination_country_code'], $packageValues['destination_country_code']); |
||
165 | |||
166 | $shipment = new Shipment(); |
||
167 | |||
168 | $shipper = $shipment->getShipper(); |
||
169 | $shipper->setShipperNumber($packageValues['account']); |
||
170 | |||
171 | $shipperAddress = $shipment->getShipper()->getAddress(); |
||
172 | $shipperAddress->setPostalCode($packageValues['origination_postcode']); |
||
173 | $shipperAddress->setAddressLine1($packageValues['origination_address']); |
||
174 | $shipperAddress->setCity($packageValues['origination_city']); |
||
175 | $shipperAddress->setCountryCode($packageValues['origination_country_code']); |
||
176 | |||
177 | $address = new Address(); |
||
178 | $address->setPostalCode($packageValues['origination_postcode']); |
||
179 | $address->setCountryCode($packageValues['origination_country_code']); |
||
180 | $address->setCity($packageValues['origination_city']); |
||
181 | $address->setStateProvinceCode($packageValues['origination_city']); |
||
182 | |||
183 | $shipFrom = new ShipFrom(); |
||
184 | $shipFrom->setAddress($address); |
||
185 | |||
186 | $shipment->setShipFrom($shipFrom); |
||
187 | |||
188 | $shipTo = $shipment->getShipTo(); |
||
189 | $shipToAddress = $shipTo->getAddress(); |
||
190 | $shipToAddress->setCountryCode($packageValues['destination_country_code']); |
||
191 | $shipToAddress->setCity($packageValues['destination_city']); |
||
192 | $shipToAddress->setPostalCode($packageValues['destination_postcode']); |
||
193 | $shipToAddress->setResidentialAddressIndicator($packageValues['destination_address']); |
||
194 | |||
195 | $pounds = $packageValues['weight'] *2.20462; |
||
196 | |||
197 | $package = new Package(); |
||
198 | $package->getPackagingType()->setCode($packageValues['type']); |
||
199 | |||
200 | |||
201 | $package->getPackageWeight()->setWeight((string)$pounds); |
||
202 | $weightUnit = new UnitOfMeasurement(); |
||
203 | $weightUnit->setCode(UnitOfMeasurement::UOM_LBS); |
||
204 | $package->getPackageWeight()->setUnitOfMeasurement($weightUnit); |
||
205 | |||
206 | $dimensions = new Dimensions(); |
||
207 | $dimensions->setHeight($packageValues['height']); |
||
208 | $dimensions->setWidth($packageValues['width']); |
||
209 | $dimensions->setLength($packageValues['length']); |
||
210 | |||
211 | $unit = new UnitOfMeasurement(); |
||
212 | $unit->setCode(UnitOfMeasurement::UOM_IN); |
||
213 | |||
214 | $dimensions->setUnitOfMeasurement($unit); |
||
215 | $package->setDimensions($dimensions); |
||
216 | |||
217 | $shipment->addPackage($package); |
||
218 | |||
219 | $service = new Service(); |
||
220 | $service->setCode($packageValues['service_code']); |
||
221 | |||
222 | $shipment->setService($service); |
||
223 | $object = new \stdClass(); |
||
224 | $object->NegotiatedRatesIndicator = true; |
||
225 | |||
226 | $shipment->setRateInformation(new RateInformation($object)); |
||
227 | |||
228 | /** @var RateResponse $rateResponse */ |
||
229 | $rateResponse = $rate->getRate($shipment); |
||
230 | |||
231 | /** @var RatedShipment $ratedShipment */ |
||
232 | $ratedShipment = $rateResponse->RatedShipment[0]; |
||
233 | |||
234 | if ($ratedShipment->NegotiatedRates) { |
||
235 | $monetaryValue = $ratedShipment->NegotiatedRates->NetSummaryCharges->GrandTotal->MonetaryValue; |
||
236 | } else { |
||
237 | $monetaryValue = $ratedShipment->TotalCharges->MonetaryValue; |
||
238 | } |
||
239 | |||
240 | return $monetaryValue; |
||
241 | } |
||
251 |