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