Conditions | 54 |
Paths | > 20000 |
Total Lines | 267 |
Code Lines | 148 |
Lines | 0 |
Ratio | 0 % |
Changes | 13 | ||
Bugs | 1 | Features | 8 |
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 |
||
108 | private function createConfirmRequest( |
||
109 | $validation, |
||
110 | Shipment $shipment, |
||
111 | ShipmentRequestLabelSpecification $labelSpec = null, |
||
112 | ShipmentRequestReceiptSpecification $receiptSpec = null |
||
113 | ) { |
||
114 | $xml = new DOMDocument(); |
||
115 | $xml->formatOutput = true; |
||
116 | |||
117 | // Page 45 |
||
118 | $container = $xml->appendChild($xml->createElement('ShipmentConfirmRequest')); |
||
119 | |||
120 | // Page 45 |
||
121 | $request = $container->appendChild($xml->createElement('Request')); |
||
122 | |||
123 | $node = $xml->importNode($this->createTransactionNode(), true); |
||
124 | $request->appendChild($node); |
||
125 | |||
126 | $request->appendChild($xml->createElement('RequestAction', 'ShipConfirm')); |
||
127 | $request->appendChild($xml->createElement('RequestOption', $validation ?: 'nonvalidate')); |
||
128 | |||
129 | // Page 47 |
||
130 | $shipmentNode = $container->appendChild($xml->createElement('Shipment')); |
||
131 | |||
132 | if ($shipment->getDescription()) { |
||
133 | $shipmentNode->appendChild($xml->createElement('Description', $shipment->getDescription())); |
||
134 | } |
||
135 | |||
136 | $returnService = $shipment->getReturnService(); |
||
137 | if (isset($returnService)) { |
||
138 | $node = $shipmentNode->appendChild($xml->createElement('ReturnService')); |
||
139 | |||
140 | $node->appendChild($xml->createElement('Code', $returnService->getCode())); |
||
141 | } |
||
142 | |||
143 | if ($shipment->getDocumentsOnly()) { |
||
144 | $shipmentNode->appendChild($xml->createElement('DocumentsOnly')); |
||
145 | } |
||
146 | |||
147 | $shipperNode = $shipmentNode->appendChild($xml->createElement('Shipper')); |
||
148 | |||
149 | $shipperNode->appendChild($xml->createElement('Name', $shipment->getShipper()->getName())); |
||
150 | |||
151 | if ($shipment->getShipper()->getAttentionName()) { |
||
152 | $shipperNode->appendChild($xml->createElement('AttentionName', $shipment->getShipper()->getAttentionName())); |
||
153 | } |
||
154 | |||
155 | if ($shipment->getShipper()->getCompanyName()) { |
||
156 | $shipperNode->appendChild($xml->createElement('CompanyDisplayableName', $shipment->getShipper()->getCompanyName())); |
||
157 | } |
||
158 | |||
159 | $shipperNode->appendChild($xml->createElement('ShipperNumber', $shipment->getShipper()->getShipperNumber())); |
||
160 | |||
161 | if ($shipment->getShipper()->getTaxIdentificationNumber()) { |
||
162 | $shipperNode->appendChild($xml->createElement('TaxIdentificationNumber', $shipment->getShipper()->getTaxIdentificationNumber())); |
||
163 | } |
||
164 | |||
165 | if ($shipment->getShipper()->getPhoneNumber()) { |
||
166 | $shipperNode->appendChild($xml->createElement('PhoneNumber', $shipment->getShipper()->getPhoneNumber())); |
||
167 | } |
||
168 | |||
169 | if ($shipment->getShipper()->getFaxNumber()) { |
||
170 | $shipperNode->appendChild($xml->createElement('FaxNumber', $shipment->getShipper()->getFaxNumber())); |
||
171 | } |
||
172 | |||
173 | if ($shipment->getShipper()->getEMailAddress()) { |
||
174 | $shipperNode->appendChild($xml->createElement('EMailAddress', $shipment->getShipper()->getEMailAddress())); |
||
175 | } |
||
176 | |||
177 | $shipperNode->appendChild($shipment->getShipper()->getAddress()->toNode($xml)); |
||
178 | |||
179 | $shipToNode = $shipmentNode->appendChild($xml->createElement('ShipTo')); |
||
180 | |||
181 | $shipToNode->appendChild($xml->createElement('CompanyName', $shipment->getShipTo()->getCompanyName())); |
||
182 | |||
183 | if ($shipment->getShipTo()->getAttentionName()) { |
||
184 | $shipToNode->appendChild($xml->createElement('AttentionName', $shipment->getShipTo()->getAttentionName())); |
||
185 | } |
||
186 | |||
187 | if ($shipment->getShipTo()->getPhoneNumber()) { |
||
188 | $shipToNode->appendChild($xml->createElement('PhoneNumber', $shipment->getShipTo()->getPhoneNumber())); |
||
189 | } |
||
190 | |||
191 | if ($shipment->getShipTo()->getFaxNumber()) { |
||
192 | $shipToNode->appendChild($xml->createElement('FaxNumber', $shipment->getShipTo()->getFaxNumber())); |
||
193 | } |
||
194 | |||
195 | if ($shipment->getShipTo()->getEMailAddress()) { |
||
196 | $shipToNode->appendChild($xml->createElement('EMailAddress', $shipment->getShipTo()->getEMailAddress())); |
||
197 | } |
||
198 | |||
199 | $addressNode = $shipment->getShipTo()->getAddress()->toNode($xml); |
||
200 | |||
201 | if ($shipment->getShipTo()->getLocationID()) { |
||
202 | $addressNode->appendChild($xml->createElement('LocationID', strtoupper($shipment->getShipTo()->getLocationID()))); |
||
203 | } |
||
204 | |||
205 | $shipToNode->appendChild($addressNode); |
||
206 | |||
207 | if ($shipment->getShipFrom()) { |
||
208 | $shipFromNode = $shipmentNode->appendChild($xml->createElement('ShipFrom')); |
||
209 | |||
210 | $shipFromNode->appendChild($xml->createElement('CompanyName', $shipment->getShipFrom()->getCompanyName())); |
||
211 | |||
212 | if ($shipment->getShipFrom()->getAttentionName()) { |
||
213 | $shipFromNode->appendChild($xml->createElement('AttentionName', $shipment->getShipFrom()->getAttentionName())); |
||
214 | } |
||
215 | |||
216 | if ($shipment->getShipFrom()->getPhoneNumber()) { |
||
217 | $shipFromNode->appendChild($xml->createElement('PhoneNumber', $shipment->getShipFrom()->getPhoneNumber())); |
||
218 | } |
||
219 | |||
220 | if ($shipment->getShipFrom()->getFaxNumber()) { |
||
221 | $shipFromNode->appendChild($xml->createElement('FaxNumber', $shipment->getShipFrom()->getFaxNumber())); |
||
222 | } |
||
223 | |||
224 | $shipFromNode->appendChild($shipment->getShipFrom()->getAddress()->toNode($xml)); |
||
225 | } |
||
226 | |||
227 | if ($shipment->getSoldTo()) { |
||
228 | $soldToNode = $shipmentNode->appendChild($xml->createElement('SoldTo')); |
||
229 | |||
230 | if ($shipment->getSoldTo()->getOption()) { |
||
231 | $soldToNode->appendChild($xml->createElement('Option', $shipment->getSoldTo()->getOption())); |
||
232 | } |
||
233 | |||
234 | $soldToNode->appendChild($xml->createElement('CompanyName', $shipment->getSoldTo()->getCompanyName())); |
||
235 | |||
236 | if ($shipment->getSoldTo()->getAttentionName()) { |
||
237 | $soldToNode->appendChild($xml->createElement('AttentionName', $shipment->getSoldTo()->getAttentionName())); |
||
238 | } |
||
239 | |||
240 | if ($shipment->getSoldTo()->getPhoneNumber()) { |
||
241 | $soldToNode->appendChild($xml->createElement('PhoneNumber', $shipment->getSoldTo()->getPhoneNumber())); |
||
242 | } |
||
243 | |||
244 | if ($shipment->getSoldTo()->getFaxNumber()) { |
||
245 | $soldToNode->appendChild($xml->createElement('FaxNumber', $shipment->getSoldTo()->getFaxNumber())); |
||
246 | } |
||
247 | |||
248 | if ($shipment->getSoldTo()->getAddress()) { |
||
249 | $soldToNode->appendChild($shipment->getSoldTo()->getAddress()->toNode($xml)); |
||
250 | } |
||
251 | } |
||
252 | |||
253 | $alternate = $shipment->getAlternateDeliveryAddress(); |
||
254 | if (isset($alternate)) { |
||
255 | $shipmentNode->appendChild($alternate->toNode($xml)); |
||
256 | } |
||
257 | |||
258 | if ($shipment->getPaymentInformation()) { |
||
259 | $paymentNode = $shipmentNode->appendChild($xml->createElement('PaymentInformation')); |
||
260 | |||
261 | if ($shipment->getPaymentInformation()->getPrepaid()) { |
||
262 | $node = $paymentNode->appendChild($xml->createElement('Prepaid')); |
||
263 | $node = $node->appendChild($xml->createElement('BillShipper')); |
||
264 | |||
265 | $billShipper = $shipment->getPaymentInformation()->getPrepaid()->getBillShipper(); |
||
266 | if (isset($billShipper) && $shipment->getPaymentInformation()->getPrepaid()->getBillShipper()->getAccountNumber()) { |
||
267 | $node->appendChild($xml->createElement('AccountNumber', $shipment->getPaymentInformation()->getPrepaid()->getBillShipper()->getAccountNumber())); |
||
268 | } elseif (isset($billShipper) && $shipment->getPaymentInformation()->getPrepaid()->getBillShipper()->getCreditCard()) { |
||
269 | $ccNode = $node->appendChild($xml->createElement('CreditCard')); |
||
270 | $ccNode->appendChild($xml->createElement('Type', $shipment->getPaymentInformation()->getPrepaid()->getBillShipper()->getCreditCard()->getType())); |
||
271 | $ccNode->appendChild($xml->createElement('Number', $shipment->getPaymentInformation()->getPrepaid()->getBillShipper()->getCreditCard()->getNumber())); |
||
272 | $ccNode->appendChild($xml->createElement('ExpirationDate', $shipment->getPaymentInformation()->getPrepaid()->getBillShipper()->getCreditCard()->getExpirationDate())); |
||
273 | |||
274 | if ($shipment->getPaymentInformation()->getPrepaid()->getBillShipper()->getCreditCard()->getSecurityCode()) { |
||
275 | $ccNode->appendChild($xml->createElement('SecurityCode', $shipment->getPaymentInformation()->getPrepaid()->getBillShipper()->getCreditCard()->getSecurityCode())); |
||
276 | } |
||
277 | |||
278 | if ($shipment->getPaymentInformation()->getPrepaid()->getBillShipper()->getCreditCard()->getAddress()) { |
||
279 | $ccNode->appendChild($shipment->getPaymentInformation()->getPrepaid()->getBillShipper()->getCreditCard()->getAddress()->toNode($xml)); |
||
280 | } |
||
281 | } |
||
282 | } elseif ($shipment->getPaymentInformation()->getBillThirdParty()) { |
||
283 | $node = $paymentNode->appendChild($xml->createElement('BillThirdParty')); |
||
284 | $btpNode = $node->appendChild($xml->createElement('BillThirdPartyShipper')); |
||
285 | $btpNode->appendChild($xml->createElement('AccountNumber', $shipment->getPaymentInformation()->getBillThirdParty()->getAccountNumber())); |
||
286 | |||
287 | $tpNode = $btpNode->appendChild($xml->createElement('ThirdParty')); |
||
288 | $addressNode = $tpNode->appendChild($xml->createElement('Address')); |
||
289 | |||
290 | $thirdPartAddress = $shipment->getPaymentInformation()->getBillThirdParty()->getThirdPartyAddress(); |
||
291 | if (isset($thirdPartAddress) && $shipment->getPaymentInformation()->getBillThirdParty()->getThirdPartyAddress()->getPostalCode()) { |
||
292 | $addressNode->appendChild($xml->createElement('PostalCode', $shipment->getPaymentInformation()->getBillThirdParty()->getThirdPartyAddress()->getPostalCode())); |
||
293 | } |
||
294 | |||
295 | $addressNode->appendChild($xml->createElement('CountryCode', $shipment->getPaymentInformation()->getBillThirdParty()->getThirdPartyAddress()->getCountryCode())); |
||
296 | } elseif ($shipment->getPaymentInformation()->getFreightCollect()) { |
||
297 | $node = $paymentNode->appendChild($xml->createElement('FreightCollect')); |
||
298 | $brNode = $node->appendChild($xml->createElement('BillReceiver')); |
||
299 | $brNode->appendChild($xml->createElement('AccountNumber', $shipment->getPaymentInformation()->getFreightCollect()->getAccountNumber())); |
||
300 | |||
301 | if ($shipment->getPaymentInformation()->getFreightCollect()->getBillReceiverAddress()) { |
||
302 | $addressNode = $brNode->appendChild($xml->createElement('Address')); |
||
303 | $addressNode->appendChild($xml->createElement('PostalCode', $shipment->getPaymentInformation()->getFreightCollect()->getBillReceiverAddress()->getPostalCode())); |
||
304 | } |
||
305 | } elseif ($shipment->getPaymentInformation()->getConsigneeBilled()) { |
||
306 | $paymentNode->appendChild($xml->createElement('ConsigneeBilled')); |
||
307 | } |
||
308 | // TODO: create ItemizedPaymentInformation class and required subclasses for node processing |
||
309 | // } elseif ($shipment->getItemizedPaymentInformation()) { |
||
310 | // $paymentNode = $shipmentNode->appendChild($xml->createElement('ItemizedPaymentInformation')); |
||
311 | } |
||
312 | |||
313 | if ($shipment->getGoodsNotInFreeCirculationIndicator()) { |
||
314 | $shipmentNode->appendChild($xml->createElement('GoodsNotInFreeCirculationIndicator')); |
||
315 | } |
||
316 | |||
317 | if ($shipment->getMovementReferenceNumber()) { |
||
318 | $shipmentNode->appendChild($xml->createElement('MovementReferenceNumber', $shipment->getMovementReferenceNumber())); |
||
319 | } |
||
320 | |||
321 | $serviceNode = $shipmentNode->appendChild($xml->createElement('Service')); |
||
322 | $serviceNode->appendChild($xml->createElement('Code', $shipment->getService()->getCode())); |
||
323 | |||
324 | if ($shipment->getService()->getDescription()) { |
||
325 | $serviceNode->appendChild($xml->createElement('Description', $shipment->getService()->getDescription())); |
||
326 | } |
||
327 | |||
328 | if ($shipment->getInvoiceLineTotal()) { |
||
329 | $shipmentNode->appendChild($shipment->getInvoiceLineTotal()->toNode($xml)); |
||
330 | } |
||
331 | |||
332 | if ($shipment->getNumOfPiecesInShipment()) { |
||
333 | $shipmentNode->appendChild($xml->createElement('NumOfPiecesInShipment', $shipment->getNumOfPiecesInShipment())); |
||
334 | } |
||
335 | |||
336 | if ($shipment->getRateInformation()) { |
||
337 | $node = $shipmentNode->appendChild($xml->createElement('RateInformation')); |
||
338 | $node->appendChild($xml->createElement('NegotiatedRatesIndicator')); |
||
339 | } |
||
340 | |||
341 | foreach ($shipment->getPackages() as $package) { |
||
342 | $shipmentNode->appendChild($xml->importNode($package->toNode($xml), true)); |
||
343 | } |
||
344 | |||
345 | $shipmentServiceOptions = $shipment->getShipmentServiceOptions(); |
||
346 | if (isset($shipmentServiceOptions)) { |
||
347 | $shipmentNode->appendChild($shipmentServiceOptions->toNode($xml)); |
||
348 | } |
||
349 | |||
350 | $referenceNumber = $shipment->getReferenceNumber(); |
||
351 | if (isset($referenceNumber)) { |
||
352 | $shipmentNode->appendChild($referenceNumber->toNode($xml)); |
||
353 | } |
||
354 | |||
355 | $referenceNumber2 = $shipment->getReferenceNumber2(); |
||
356 | if (isset($referenceNumber2)) { |
||
357 | $shipmentNode->appendChild($referenceNumber2->toNode($xml)); |
||
358 | } |
||
359 | |||
360 | if ($labelSpec) { |
||
361 | $container->appendChild($xml->importNode($this->compileLabelSpecificationNode($labelSpec), true)); |
||
362 | } |
||
363 | |||
364 | $shipmentIndicationType = $shipment->getShipmentIndicationType(); |
||
365 | if (isset($shipmentIndicationType)) { |
||
366 | $shipmentNode->appendChild($shipmentIndicationType->toNode($xml)); |
||
367 | } |
||
368 | |||
369 | if ($receiptSpec) { |
||
370 | $container->appendChild($xml->importNode($this->compileReceiptSpecificationNode($receiptSpec), true)); |
||
371 | } |
||
372 | |||
373 | return $xml->saveXML(); |
||
374 | } |
||
375 | |||
726 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.