| Conditions | 7 |
| Paths | 64 |
| Total Lines | 91 |
| 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 |
||
| 75 | private function createFromOrder(OrderInterface $syliusOrder): OrderView |
||
| 76 | { |
||
| 77 | /** @var OrderView $orderView */ |
||
| 78 | $orderView = new $this->orderViewClass(); |
||
| 79 | $orderView->applied_rule_ids = ''; |
||
| 80 | $orderView->base_currency_code = $syliusOrder->getCurrencyCode(); |
||
| 81 | $orderView->base_discount_amount = 0; |
||
| 82 | $orderView->base_grand_total = $syliusOrder->getTotal(); |
||
| 83 | $orderView->base_discount_tax_compensation_amount = 0; |
||
| 84 | $orderView->base_shipping_amount = $syliusOrder->getShippingTotal(); |
||
| 85 | $orderView->base_shipping_discount_amount = 0; |
||
| 86 | $orderView->base_shipping_incl_tax = $syliusOrder->getShippingTotal(); |
||
| 87 | $orderView->base_shipping_tax_amount = 0; |
||
| 88 | $orderView->base_subtotal = $syliusOrder->getItemsTotal(); |
||
| 89 | $orderView->base_subtotal_incl_tax = $syliusOrder->getItemsTotal(); |
||
| 90 | $orderView->base_tax_amount = $syliusOrder->getTaxTotal(); |
||
| 91 | $orderView->base_total_due = $syliusOrder->getTotal(); |
||
| 92 | $orderView->base_to_global_rate = 0; |
||
| 93 | $orderView->base_to_order_rate = 0; |
||
| 94 | $orderView->billing_address_id = $syliusOrder->getBillingAddress() ? $syliusOrder->getBillingAddress()->getId() : 1; |
||
| 95 | $orderView->created_at = $syliusOrder->getCreatedAt()->format(DateHelper::DATE_TIME_FORMAT); |
||
| 96 | $orderView->customer_email = $syliusOrder->getCustomer()->getEmail(); |
||
| 97 | $orderView->customer_firstname = $syliusOrder->getCustomer()->getFirstName(); |
||
| 98 | $orderView->customer_lastname = $syliusOrder->getCustomer()->getLastName(); |
||
| 99 | $orderView->customer_group_id = 0; |
||
| 100 | $orderView->customer_is_guest = 0; |
||
| 101 | $orderView->customer_note_notify = 0; |
||
| 102 | |||
| 103 | $orderView->discount_amount = $syliusOrder->getOrderPromotionTotal(); |
||
| 104 | |||
| 105 | $orderView->email_sent = 1; |
||
| 106 | $orderView->entity_id = $syliusOrder->getId(); |
||
| 107 | $orderView->global_currency_code = $syliusOrder->getCurrencyCode(); |
||
| 108 | $orderView->grand_total = $syliusOrder->getItemsTotal() + $syliusOrder->getShippingTotal(); |
||
| 109 | $orderView->discount_tax_compensation_amount = 0; |
||
| 110 | |||
| 111 | $orderView->increment_id = '000000000'; |
||
| 112 | if ($syliusOrder->getNumber()) { |
||
| 113 | $orderView->increment_id = $syliusOrder->getNumber(); |
||
| 114 | } |
||
| 115 | |||
| 116 | $orderView->is_virtual = 0; |
||
| 117 | $orderView->order_currency_code = $syliusOrder->getCurrencyCode(); |
||
| 118 | $orderView->protect_code = ''; |
||
| 119 | $orderView->quote_id = $syliusOrder->getId(); |
||
| 120 | $orderView->shipping_amount = $syliusOrder->getShippingTotal(); |
||
| 121 | |||
| 122 | $orderView->shipping_description = ''; |
||
| 123 | if ($syliusOrder->getShipments()->first()) { |
||
| 124 | $orderView->shipping_description = $syliusOrder->getShipments()->first()->getMethod()->getName(); |
||
| 125 | } |
||
| 126 | |||
| 127 | $orderView->shipping_discount_amount = 0; |
||
| 128 | $orderView->shipping_discount_tax_compensation_amount = 0; |
||
| 129 | $orderView->shipping_incl_tax = $syliusOrder->getShippingTotal(); |
||
| 130 | $orderView->shipping_tax_amount = 0; |
||
| 131 | $orderView->state = $syliusOrder->getState(); |
||
| 132 | $orderView->status = $syliusOrder->getCheckoutState(); |
||
| 133 | $orderView->store_currency_code = $syliusOrder->getCurrencyCode(); |
||
| 134 | $orderView->store_id = 1; |
||
| 135 | $orderView->store_name = 'Example'; |
||
| 136 | $orderView->store_to_base_rate = 0; |
||
|
|
|||
| 137 | $orderView->store_to_order_rate = 0; |
||
| 138 | $syliusOrder->recalculateItemsTotal(); |
||
| 139 | $orderView->subtotal = $syliusOrder->getItemsTotal(); |
||
| 140 | $orderView->subtotal_incl_tax = $syliusOrder->getItemsTotal(); |
||
| 141 | $orderView->tax_amount = $syliusOrder->getTaxTotal(); |
||
| 142 | $orderView->total_due = $syliusOrder->getTotal(); |
||
| 143 | $orderView->total_item_count = $syliusOrder->getTotalQuantity(); |
||
| 144 | $orderView->total_qty_ordered = $syliusOrder->getTotalQuantity(); |
||
| 145 | $orderView->updated_at = $syliusOrder->getUpdatedAt() ? $syliusOrder->getUpdatedAt()->format(DateHelper::DATE_TIME_FORMAT) : null; |
||
| 146 | $orderView->weight = 5; |
||
| 147 | $orderView->items = $this->cartItemViewFactory->createList($syliusOrder->getItems()); |
||
| 148 | |||
| 149 | if ($syliusOrder->getBillingAddress()) { |
||
| 150 | $orderView->billing_address = $this->addressViewFactory->create($syliusOrder->getBillingAddress()); |
||
| 151 | } else { |
||
| 152 | $orderView->billing_address = new AddressView(); |
||
| 153 | } |
||
| 154 | |||
| 155 | if ($syliusOrder->getPayments()->first()) { |
||
| 156 | $orderView->payment = $this->paymentViewFactory->create($syliusOrder->getPayments()->first()); |
||
| 157 | } else { |
||
| 158 | $orderView->payment = new PaymentView(); |
||
| 159 | } |
||
| 160 | |||
| 161 | $orderView->status_histories = []; |
||
| 162 | $orderView->extension_attributes = $this->orderExtensionAttributesViewFactory->create($syliusOrder); |
||
| 163 | |||
| 164 | return $orderView; |
||
| 165 | } |
||
| 166 | } |
||
| 167 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.