Conditions | 10 |
Paths | 12 |
Total Lines | 67 |
Code Lines | 40 |
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 |
||
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 | if ($this->nextStep() && !$this->cartMode == 'single_page') { |
||
141 | // form for the next step |
||
142 | $form = $this->createForm(); |
||
143 | } else { |
||
144 | // flow finished |
||
145 | /** @var SkuskuCart $finalCart */ |
||
146 | $finalCart = $formData->getCart(); |
||
147 | |||
148 | if ($this->hasListeners(self::PRE_SUBMIT)) { |
||
149 | $event = new PreSubmitCartEvent($this, $finalCart); |
||
150 | $this->eventDispatcher->dispatch(self::PRE_SUBMIT, $event); |
||
151 | } |
||
152 | |||
153 | $this->cartManager->persistCart($finalCart); |
||
154 | |||
155 | $storage = $this->payum->getStorage('GGGGino\SkuskuCartBundle\Model\SkuskuPayment'); |
||
156 | |||
157 | $payment = new SkuskuPayment(); |
||
158 | $payment->setNumber(uniqid()); |
||
159 | $payment->setCurrencyCode($finalCart->getCurrency()->getIsoCode()); |
||
160 | $payment->setTotalAmount($finalCart->getTotalPrice()); // 1.23 EUR |
||
161 | $payment->setDescription($finalCart->getTotalQuantity()); |
||
162 | $payment->setClientId($finalCart->getCustomer()); |
||
163 | $payment->setClientEmail($finalCart->getCustomer()->getEmail()); |
||
164 | |||
165 | $storage->update($payment); |
||
166 | |||
167 | $captureToken = $this->payum->getTokenFactory()->createCaptureToken( |
||
168 | $formData->getPaymentMethod(), |
||
169 | $payment, |
||
170 | 'done' // the route to redirect after capture |
||
171 | ); |
||
172 | |||
173 | $finalCart->setPayment($payment); |
||
174 | |||
175 | $requestFields = $this->requestStack->getCurrentRequest()->request->get('choosePayment'); |
||
176 | if(isset($requestFields['additionalFields']) && count($requestFields['additionalFields']) > 0 ) { |
||
177 | $finalCart->setAdditionalFields(json_encode($requestFields['additionalFields'])); |
||
178 | } |
||
179 | |||
180 | $this->cartManager->flushCart($finalCart); |
||
181 | |||
182 | $this->reset(); // remove step data from the session |
||
183 | |||
184 | if ($this->hasListeners(self::POST_SUBMIT)) { |
||
185 | $event = new PostSubmitCartEvent($this, $finalCart); |
||
186 | $this->eventDispatcher->dispatch(self::POST_SUBMIT, $event); |
||
187 | } |
||
188 | |||
189 | return new RedirectResponse($captureToken->getTargetUrl()); |
||
190 | } |
||
267 | } |