| Conditions | 2 |
| Paths | 2 |
| Total Lines | 95 |
| Code Lines | 70 |
| 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 |
||
| 72 | public function createPaymentFromDandomainPaymentRequest(PaymentRequest $paymentRequest) : PaymentInterface |
||
| 73 | { |
||
| 74 | $order = $this->orderManager->create(); |
||
| 75 | |||
| 76 | |||
| 77 | $site = $this->siteManager->findByExternalId($paymentRequest->getLanguageId()); |
||
| 78 | $order->setExternalId($paymentRequest->getOrderId()); |
||
| 79 | $order->setCurrencyCode($paymentRequest->getCurrencySymbol()); |
||
| 80 | $order->setIp($paymentRequest->getCustomerIp()); |
||
| 81 | //$order->setLoadBalancerRealIp($paymentRequest->getLoadBalancerRealIp()); |
||
|
|
|||
| 82 | $order->setSite($site); |
||
| 83 | |||
| 84 | // create customer object |
||
| 85 | $customer = $this->customerManager->create(); |
||
| 86 | //$customer->setCustomerRekvNr($paymentRequest->getCustomerRekvNr()); @todo ask Dandomain why this field is not present on the customer object |
||
| 87 | $customer->setAttention($paymentRequest->getCustomerName()); |
||
| 88 | $customer->setName($paymentRequest->getCustomerCompany()); |
||
| 89 | $customer->setAddress($paymentRequest->getCustomerAddress()); |
||
| 90 | $customer->setAddress2($paymentRequest->getCustomerAddress2()); |
||
| 91 | $customer->setZipCode($paymentRequest->getCustomerZipCode()); |
||
| 92 | $customer->setCity($paymentRequest->getCustomerCity()); |
||
| 93 | $customer->setCountryId((int)$paymentRequest->getCustomerCountryId()); |
||
| 94 | $customer->setCountry($paymentRequest->getCustomerCountry()); |
||
| 95 | $customer->setPhone($paymentRequest->getCustomerPhone()); |
||
| 96 | $customer->setFax($paymentRequest->getCustomerFax()); |
||
| 97 | $customer->setEmail($paymentRequest->getCustomerEmail()); |
||
| 98 | $customer->setComments($paymentRequest->getCustomerNote()); |
||
| 99 | $customer->setCvr($paymentRequest->getCustomerCvrnr()); |
||
| 100 | //$customer->setCustomerCustTypeId($paymentRequest->getCustomerCustTypeId()); @todo figure out what this field is |
||
| 101 | $customer->setEan($paymentRequest->getCustomerEan()); |
||
| 102 | $customer->setReservedField1($paymentRequest->getCustomerRes1()); |
||
| 103 | $customer->setReservedField2($paymentRequest->getCustomerRes2()); |
||
| 104 | $customer->setReservedField3($paymentRequest->getCustomerRes3()); |
||
| 105 | $customer->setReservedField4($paymentRequest->getCustomerRes4()); |
||
| 106 | $customer->setReservedField5($paymentRequest->getCustomerRes5()); |
||
| 107 | |||
| 108 | // add customer to order |
||
| 109 | $order->setCustomer($customer); |
||
| 110 | |||
| 111 | // create delivery object |
||
| 112 | $delivery = $this->deliveryManager->create(); |
||
| 113 | $delivery->setAttention($paymentRequest->getDeliveryName()); |
||
| 114 | $delivery->setName($paymentRequest->getDeliveryCompany()); |
||
| 115 | $delivery->setAddress($paymentRequest->getDeliveryAddress()); |
||
| 116 | $delivery->setAddress2($paymentRequest->getDeliveryAddress2()); |
||
| 117 | $delivery->setZipCode($paymentRequest->getDeliveryZipCode()); |
||
| 118 | $delivery->setCity($paymentRequest->getDeliveryCity()); |
||
| 119 | $delivery->setCountryId((int)$paymentRequest->getDeliveryCountryID()); |
||
| 120 | $delivery->setCountry($paymentRequest->getDeliveryCountry()); |
||
| 121 | $delivery->setPhone($paymentRequest->getDeliveryPhone()); |
||
| 122 | $delivery->setFax($paymentRequest->getDeliveryFax()); |
||
| 123 | $delivery->setEmail($paymentRequest->getDeliveryEmail()); |
||
| 124 | $delivery->setEan($paymentRequest->getDeliveryEan()); |
||
| 125 | |||
| 126 | // create shipping method object |
||
| 127 | // @todo figure out if the payment request from Dandomain contains a payment method id (check also shipping method) |
||
| 128 | //$shippingMethod = $this->shippingMethodManager->findByExternalId($paymentRequest->ship) |
||
| 129 | $order->setShippingMethod($paymentRequest->getShippingMethod()); |
||
| 130 | $order->setShippingMethodFee($paymentRequest->getShippingFee()); |
||
| 131 | $order->setPaymentMethod($paymentRequest->getPaymentMethod()); |
||
| 132 | $order->setPaymentMethodFee($paymentRequest->getPaymentFee()); |
||
| 133 | |||
| 134 | // add delivery to order |
||
| 135 | $order->setDelivery($delivery); |
||
| 136 | |||
| 137 | foreach ($paymentRequest->getOrderLines() as $orderLine) { |
||
| 138 | $orderLineEntity = $this->orderLineManager->create(); |
||
| 139 | $orderLineEntity |
||
| 140 | ->setProductNumber($orderLine->getProductNumber()) |
||
| 141 | ->setProductName($orderLine->getName()) |
||
| 142 | ->setQuantity($orderLine->getQuantity()) |
||
| 143 | ->setUnitPrice($orderLine->getPrice()) |
||
| 144 | ->setVatPct($orderLine->getVat()) |
||
| 145 | ; |
||
| 146 | $order->addOrderLine($orderLineEntity); |
||
| 147 | } |
||
| 148 | |||
| 149 | // create payment object |
||
| 150 | $payment = $this->create(); |
||
| 151 | $payment->setApiKey($paymentRequest->getApiKey()); |
||
| 152 | $payment->setMerchant($paymentRequest->getMerchant()); |
||
| 153 | $payment->setSessionId($paymentRequest->getSessionId()); |
||
| 154 | $payment->setCurrencySymbol($paymentRequest->getCurrencySymbol()); |
||
| 155 | $payment->setTotalAmount($paymentRequest->getTotalAmount()); |
||
| 156 | $payment->setCallBackUrl($paymentRequest->getCallBackUrl()); |
||
| 157 | $payment->setFullCallBackOkUrl($paymentRequest->getFullCallBackOkUrl()); |
||
| 158 | $payment->setCallBackOkUrl($paymentRequest->getCallBackOkUrl()); |
||
| 159 | $payment->setCallBackServerUrl($paymentRequest->getCallBackServerUrl()); |
||
| 160 | $payment->setTestMode($paymentRequest->isTestMode()); |
||
| 161 | $payment->setPaymentGatewayCurrencyCode($paymentRequest->getPaymentGatewayCurrencyCode()); |
||
| 162 | $payment->setCardTypeId($paymentRequest->getCardTypeId()); |
||
| 163 | $payment->setOrder($order); |
||
| 164 | |||
| 165 | return $payment; |
||
| 166 | } |
||
| 167 | |||
| 253 | } |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.