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