| Conditions | 5 | 
| Paths | 16 | 
| Total Lines | 53 | 
| Code Lines | 32 | 
| 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->shippingState = $order->getShippingState(); | ||
| 78 | $orderView->paymentState = $order->getPaymentState(); | ||
| 79 | |||
| 80 | /** @var ShipmentInterface $shipment */ | ||
| 81 |         foreach ($order->getShipments() as $shipment) { | ||
| 82 | $orderView->shipments[] = $this->shipmentViewFactory->create($shipment, $localeCode); | ||
| 83 | } | ||
| 84 | |||
| 85 | /** @var PaymentInterface $payment */ | ||
| 86 |         foreach ($order->getPayments() as $payment) { | ||
| 87 | $orderView->payments[] = $this->paymentViewFactory->create($payment, $localeCode); | ||
| 88 | } | ||
| 89 | |||
| 90 |         if (null !== $order->getShippingAddress()) { | ||
| 91 | $orderView->shippingAddress = $this->addressViewFactory->create($order->getShippingAddress()); | ||
| 92 | } | ||
| 93 | |||
| 94 |         if (null !== $order->getBillingAddress()) { | ||
| 95 | $orderView->billingAddress = $this->addressViewFactory->create($order->getBillingAddress()); | ||
| 96 | } | ||
| 97 | |||
| 98 | $orderView->total = $order->getTotal(); | ||
| 99 | $orderView->customer = $this->customerViewFactory->create($customer); | ||
| 100 | |||
| 101 | return $orderView; | ||
| 102 | } | ||
| 104 |