| Conditions | 5 |
| Paths | 1 |
| Total Lines | 60 |
| Code Lines | 37 |
| 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 declare(strict_types=1); |
||
| 103 | private function setPaymentMethod(string $paymentMethodId, string $orderId, SalesChannelContext $salesChannelContext): void |
||
| 104 | { |
||
| 105 | $context = $salesChannelContext->getContext(); |
||
| 106 | $initialState = $this->stateMachineRegistry->getInitialState( |
||
| 107 | OrderTransactionStates::STATE_MACHINE, |
||
| 108 | $context |
||
| 109 | ); |
||
| 110 | |||
| 111 | $criteria = new Criteria([$orderId]); |
||
| 112 | $criteria->addAssociation('transactions'); |
||
| 113 | |||
| 114 | /** @var CustomerEntity $customer */ |
||
| 115 | $customer = $salesChannelContext->getCustomer(); |
||
| 116 | |||
| 117 | $criteria->addFilter( |
||
| 118 | new EqualsFilter( |
||
| 119 | 'order.orderCustomer.customerId', |
||
| 120 | $customer->getId() |
||
| 121 | ) |
||
| 122 | ); |
||
| 123 | |||
| 124 | /** @var OrderEntity $order */ |
||
| 125 | $order = $this->orderRepository->search($criteria, $context)->first(); |
||
| 126 | |||
| 127 | $context->scope( |
||
| 128 | Context::SYSTEM_SCOPE, |
||
| 129 | function () use ($order, $initialState, $orderId, $paymentMethodId, $context): void { |
||
| 130 | if ($order->getTransactions() !== null && $order->getTransactions()->count() >= 1) { |
||
| 131 | foreach ($order->getTransactions() as $transaction) { |
||
| 132 | if ($transaction->getStateMachineState()->getTechnicalName() !== OrderTransactionStates::STATE_CANCELLED) { |
||
| 133 | $this->orderService->orderTransactionStateTransition( |
||
| 134 | $transaction->getId(), |
||
| 135 | 'cancel', |
||
| 136 | new ParameterBag(), |
||
| 137 | $context |
||
| 138 | ); |
||
| 139 | } |
||
| 140 | } |
||
| 141 | } |
||
| 142 | $transactionId = Uuid::randomHex(); |
||
| 143 | $transactionAmount = new CalculatedPrice( |
||
| 144 | $order->getPrice()->getTotalPrice(), |
||
| 145 | $order->getPrice()->getTotalPrice(), |
||
| 146 | $order->getPrice()->getCalculatedTaxes(), |
||
| 147 | $order->getPrice()->getTaxRules() |
||
| 148 | ); |
||
| 149 | |||
| 150 | $this->orderRepository->update([ |
||
| 151 | [ |
||
| 152 | 'id' => $orderId, |
||
| 153 | 'transactions' => [ |
||
| 154 | [ |
||
| 155 | 'id' => $transactionId, |
||
| 156 | 'paymentMethodId' => $paymentMethodId, |
||
| 157 | 'stateId' => $initialState->getId(), |
||
| 158 | 'amount' => $transactionAmount, |
||
| 159 | ], |
||
| 160 | ], |
||
| 161 | ], |
||
| 162 | ], $context); |
||
| 163 | } |
||
| 179 |