| Conditions | 8 |
| Paths | 32 |
| Total Lines | 66 |
| Code Lines | 53 |
| 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 |
||
| 20 | public function execute($request): void |
||
| 21 | { |
||
| 22 | RequestNotSupportedException::assertSupports($this, $request); |
||
| 23 | |||
| 24 | /** @var PaymentInterface $payment */ |
||
| 25 | $payment = $request->getSource(); |
||
| 26 | |||
| 27 | $order = $payment->getOrder(); |
||
| 28 | |||
| 29 | $details = [ |
||
| 30 | 'iyzico_id' => $order->getId(), |
||
| 31 | 'iyzico_currency_code' => $order->getCurrencyCode(), |
||
|
|
|||
| 32 | 'iyzico_order_number' => $order->getNumber(), |
||
| 33 | 'iyzico_total' => $order->getTotal() / 100, |
||
| 34 | 'iyzico_local_code' => explode("_", $order->getLocaleCode())[0], |
||
| 35 | 'iyzico_target_url' => $request->getToken()->getTargetUrl(), |
||
| 36 | 'iyzico_shipping_address' => [ |
||
| 37 | "firstname" => $order->getShippingAddress()->getFirstName(), |
||
| 38 | "lastname" => $order->getShippingAddress()->getLastName(), |
||
| 39 | "country_code" => $order->getShippingAddress()->getCountryCode(), |
||
| 40 | "city" => $order->getShippingAddress()->getCity(), |
||
| 41 | "street" => $order->getShippingAddress()->getStreet(), |
||
| 42 | "postcode" => $order->getShippingAddress()->getPostcode(), |
||
| 43 | ], |
||
| 44 | 'iyzico_billing_address' => [ |
||
| 45 | 'firstname' => $order->getBillingAddress()->getFirstName(), |
||
| 46 | 'lastname' => $order->getBillingAddress()->getLastName(), |
||
| 47 | 'country_code' => $order->getBillingAddress()->getCountryCode(), |
||
| 48 | 'city' => $order->getBillingAddress()->getCity(), |
||
| 49 | 'street' => $order->getBillingAddress()->getStreet(), |
||
| 50 | 'postcode' => $order->getBillingAddress()->getPostcode(), |
||
| 51 | ], |
||
| 52 | 'iyzico_customer' => [ |
||
| 53 | 'id' => $order->getCustomer()->getId(), |
||
| 54 | 'firstname' => $order->getCustomer()->getFirstName() ? $order->getCustomer()->getFirstName() : $order->getShippingAddress()->getFirstName(), |
||
| 55 | 'lastname' => $order->getCustomer()->getLastName() ? $order->getCustomer()->getLastName() : $order->getShippingAddress()->getLastName(), |
||
| 56 | 'phone_number' => $order->getCustomer()->getPhoneNumber() ? $order->getCustomer()->getPhoneNumber() : $order->getShippingAddress()->getPhoneNumber(), |
||
| 57 | 'email' => $order->getCustomer()->getEmail(), |
||
| 58 | 'ip' => $order->getCustomerIp(), |
||
| 59 | 'last_login_date' => $order->getCustomer()->getUser() ? $order->getCustomer()->getUser()->getLastLogin() : null, |
||
| 60 | 'registration_date' => $order->getCustomer()->getCreatedAt(), |
||
| 61 | 'identity_number' => $_ENV['APP_ENV'] === 'test' ? '74300864791' : $order->getCustomer()->getIdentityNumber(), |
||
| 62 | 'country_code' => $order->getShippingAddress()->getCountryCode(), |
||
| 63 | 'city' => $order->getShippingAddress()->getCity(), |
||
| 64 | 'street' => $order->getShippingAddress()->getStreet(), |
||
| 65 | 'postcode' => $order->getShippingAddress()->getPostcode(), |
||
| 66 | ], |
||
| 67 | 'iyzico_items' => array_map(function ($orderItem) { |
||
| 68 | return [ |
||
| 69 | 'id' => $orderItem->getId(), |
||
| 70 | 'name' => $orderItem->getProductName(), |
||
| 71 | 'total' => $orderItem->getTotal() / 100, |
||
| 72 | 'category' => $orderItem->getProduct()->getMainTaxon() ? $orderItem->getProduct()->getMainTaxon()->getName() : "empty" |
||
| 73 | ]; |
||
| 74 | }, iterator_to_array($order->getItems())), |
||
| 75 | 'iyzico_shipment' => array_map(function ($shipment) use ($order) { |
||
| 76 | return [ |
||
| 77 | 'id' => $shipment->getMethod()->getId(), |
||
| 78 | 'name' => $shipment->getMethod()->getName(), |
||
| 79 | 'total' => $order->getShippingTotal() / 100, |
||
| 80 | 'category' => $shipment->getMethod()->getCategory() ? $shipment->getMethod()->getCategory()->getName() : IyzicoBridgeInterface::SHIPPING_CATEGORY |
||
| 81 | ]; |
||
| 82 | }, iterator_to_array($order->getShipments())) |
||
| 83 | ]; |
||
| 84 | |||
| 85 | $request->setResult($details); |
||
| 86 | } |
||
| 96 |