| Conditions | 10 |
| Paths | 12 |
| Total Lines | 68 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | 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 |
||
| 123 | public function handleSubmit(&$form, $formData) |
||
| 124 | { |
||
| 125 | if ($this->isValid($form)) { |
||
| 126 | $this->saveCurrentStepData($form); |
||
| 127 | |||
| 128 | |||
| 129 | if( !$this->allowAnonymous ) |
||
| 130 | throw new AccessDeniedException("Anonymous users cannot buy"); |
||
| 131 | |||
| 132 | // @todo done this because craue form flow doesn't permit to add a custom action |
||
| 133 | if( $this->requestStack->getCurrentRequest()->request->get('flow_cart_transition') == self::TRANSITION_RESET_CART ) { |
||
| 134 | $this->emptyCart($formData); |
||
| 135 | $this->reset(); |
||
| 136 | $form = $this->createForm(); |
||
| 137 | return null; |
||
| 138 | } |
||
| 139 | |||
| 140 | |||
| 141 | if ($this->nextStep() && $this->cartMode != 'single_page') { |
||
| 142 | // form for the next step |
||
| 143 | $form = $this->createForm(); |
||
| 144 | } else { |
||
| 145 | // flow finished |
||
| 146 | /** @var SkuskuCart $finalCart */ |
||
| 147 | $finalCart = $formData->getCart(); |
||
| 148 | |||
| 149 | if ($this->hasListeners(self::PRE_SUBMIT)) { |
||
| 150 | $event = new PreSubmitCartEvent($this, $finalCart); |
||
| 151 | $this->eventDispatcher->dispatch(self::PRE_SUBMIT, $event); |
||
| 152 | } |
||
| 153 | |||
| 154 | $this->cartManager->persistCart($finalCart); |
||
| 155 | |||
| 156 | $storage = $this->payum->getStorage('GGGGino\SkuskuCartBundle\Model\SkuskuPayment'); |
||
| 157 | |||
| 158 | $payment = new SkuskuPayment(); |
||
| 159 | $payment->setNumber(uniqid()); |
||
| 160 | $payment->setCurrencyCode($finalCart->getCurrency()->getIsoCode()); |
||
| 161 | $payment->setTotalAmount($finalCart->getTotalPrice()); // 1.23 EUR |
||
| 162 | $payment->setDescription($finalCart->getTotalQuantity()); |
||
| 163 | $payment->setClientId($finalCart->getCustomer()); |
||
| 164 | $payment->setClientEmail($finalCart->getCustomer()->getEmail()); |
||
| 165 | |||
| 166 | $storage->update($payment); |
||
| 167 | |||
| 168 | $captureToken = $this->payum->getTokenFactory()->createCaptureToken( |
||
| 169 | $formData->getPaymentMethod(), |
||
| 170 | $payment, |
||
| 171 | 'done' // the route to redirect after capture |
||
| 172 | ); |
||
| 173 | |||
| 174 | $finalCart->setPayment($payment); |
||
| 175 | |||
| 176 | $requestFields = $this->requestStack->getCurrentRequest()->request->get('choosePayment'); |
||
| 177 | if(isset($requestFields['additionalFields']) && count($requestFields['additionalFields']) > 0 ) { |
||
| 178 | $finalCart->setAdditionalFields(json_encode($requestFields['additionalFields'])); |
||
| 179 | } |
||
| 180 | |||
| 181 | $this->cartManager->flushCart($finalCart); |
||
| 182 | |||
| 183 | $this->reset(); // remove step data from the session |
||
| 184 | |||
| 185 | if ($this->hasListeners(self::POST_SUBMIT)) { |
||
| 186 | $event = new PostSubmitCartEvent($this, $finalCart); |
||
| 187 | $this->eventDispatcher->dispatch(self::POST_SUBMIT, $event); |
||
| 188 | } |
||
| 189 | |||
| 190 | return new RedirectResponse($captureToken->getTargetUrl()); |
||
| 191 | } |
||
| 268 | } |