| Conditions | 5 |
| Paths | 16 |
| Total Lines | 52 |
| Code Lines | 31 |
| 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 |
||
| 49 | public function create(OrderInterface $order): OrderView |
||
| 50 | { |
||
| 51 | $channel = $order->getChannel(); |
||
| 52 | Assert::notNull($channel); |
||
| 53 | |||
| 54 | $locale = $channel->getDefaultLocale(); |
||
|
|
|||
| 55 | Assert::notNull($locale); |
||
| 56 | |||
| 57 | $localeCode = $locale->getCode(); |
||
| 58 | Assert::notNull($localeCode); |
||
| 59 | |||
| 60 | $checkoutCompletedAt = $order->getCheckoutCompletedAt(); |
||
| 61 | Assert::notNull($checkoutCompletedAt); |
||
| 62 | |||
| 63 | /** @var CustomerInterface|null $customer */ |
||
| 64 | $customer = $order->getCustomer(); |
||
| 65 | Assert::notNull($customer); |
||
| 66 | |||
| 67 | /** @var OrderView $orderView */ |
||
| 68 | $orderView = new $this->orderViewClass(); |
||
| 69 | $orderView->id = $order->getId(); |
||
| 70 | $orderView->number = $order->getNumber(); |
||
| 71 | $orderView->channel = $channel->getCode(); |
||
| 72 | $orderView->currencyCode = $order->getCurrencyCode(); |
||
| 73 | $orderView->localeCode = $localeCode; |
||
| 74 | $orderView->state = $order->getState(); |
||
| 75 | $orderView->checkoutState = $order->getCheckoutState(); |
||
| 76 | $orderView->checkoutCompletedAt = $checkoutCompletedAt->format('c'); |
||
| 77 | $orderView->paymentState = $order->getPaymentState(); |
||
| 78 | |||
| 79 | /** @var ShipmentInterface $shipment */ |
||
| 80 | foreach ($order->getShipments() as $shipment) { |
||
| 81 | $orderView->shipments[] = $this->shipmentViewFactory->create($shipment, $localeCode); |
||
| 82 | } |
||
| 83 | |||
| 84 | /** @var PaymentInterface $payment */ |
||
| 85 | foreach ($order->getPayments() as $payment) { |
||
| 86 | $orderView->payments[] = $this->paymentViewFactory->create($payment, $localeCode); |
||
| 87 | } |
||
| 88 | |||
| 89 | if (null !== $order->getShippingAddress()) { |
||
| 90 | $orderView->shippingAddress = $this->addressViewFactory->create($order->getShippingAddress()); |
||
| 91 | } |
||
| 92 | |||
| 93 | if (null !== $order->getBillingAddress()) { |
||
| 94 | $orderView->billingAddress = $this->addressViewFactory->create($order->getBillingAddress()); |
||
| 95 | } |
||
| 96 | |||
| 97 | $orderView->total = $order->getTotal(); |
||
| 98 | $orderView->customer = $this->customerViewFactory->create($customer); |
||
| 99 | |||
| 100 | return $orderView; |
||
| 101 | } |
||
| 103 |