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