| Conditions | 8 |
| Paths | 6 |
| Total Lines | 76 |
| Code Lines | 49 |
| 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 |
||
| 24 | public function indexAction(Request $request) |
||
| 25 | { |
||
| 26 | $this->hasPermission(Permissions::CONFIGURE); |
||
| 27 | $em = $this->getDoctrine()->getManager(); |
||
| 28 | $preferencesService = $this->container->get('system_preferences_service'); |
||
| 29 | $translator = $this->container->get('translator'); |
||
| 30 | $active = $em->getRepository('Newscoop\PaywallBundle\Entity\Gateway') |
||
| 31 | ->findOneBy(array( |
||
| 32 | 'isActive' => true, |
||
| 33 | )); |
||
| 34 | |||
| 35 | $form = $this->container->get('form.factory')->create(new SettingsFormType(), array( |
||
| 36 | 'notificationEmail' => $preferencesService->PaywallMembershipNotifyEmail, |
||
| 37 | 'enableNotify' => $preferencesService->PaywallEmailNotifyEnabled == '1' ? true : false, |
||
| 38 | 'notificationFromEmail' => $preferencesService->PaywallMembershipNotifyFromEmail, |
||
| 39 | 'currency' => $preferencesService->PaywallDefaultCurrency, |
||
| 40 | )); |
||
| 41 | |||
| 42 | if ($request->isMethod('POST')) { |
||
| 43 | $form->bind($request); |
||
| 44 | if ($form->isValid()) { |
||
| 45 | $data = $form->getData(); |
||
| 46 | $preferencesService->set('PaywallMembershipNotifyEmail', $data['notificationEmail']); |
||
| 47 | $preferencesService->set('PaywallEmailNotifyEnabled', $data['enableNotify']); |
||
| 48 | $preferencesService->set('PaywallMembershipNotifyFromEmail', $data['notificationFromEmail']); |
||
| 49 | $preferencesService->set('PaywallDefaultCurrency', $data['currency']); |
||
| 50 | |||
| 51 | if (is_numeric($data['adapter'])) { |
||
| 52 | $settings = $em->getRepository('Newscoop\PaywallBundle\Entity\Gateway') |
||
| 53 | ->findOneBy(array( |
||
| 54 | 'id' => $data['adapter'], |
||
| 55 | )); |
||
| 56 | |||
| 57 | $all = $em->getRepository('Newscoop\PaywallBundle\Entity\Gateway') |
||
| 58 | ->findAll(); |
||
| 59 | |||
| 60 | foreach ($all as $value) { |
||
| 61 | $value->setActive(false); |
||
| 62 | } |
||
| 63 | |||
| 64 | $settings->setActive(true); |
||
| 65 | $em->flush(); |
||
| 66 | } |
||
| 67 | |||
| 68 | $this->get('session')->getFlashBag()->add('success', $translator->trans('paywall.success.settingssaved')); |
||
| 69 | |||
| 70 | return $this->redirect($this->generateUrl('newscoop_paywall_configurepaywall_index')); |
||
| 71 | } else { |
||
| 72 | $this->get('session')->getFlashBag()->add('error', $translator->trans('paywall.error.settingserror')); |
||
| 73 | |||
| 74 | return $this->redirect($this->generateUrl('newscoop_paywall_configurepaywall_index')); |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | if ($request->isXmlHttpRequest()) { |
||
| 79 | $inactive = $em->getRepository('Newscoop\PaywallBundle\Entity\Gateway') |
||
| 80 | ->findBy(array( |
||
| 81 | 'isActive' => false, |
||
| 82 | )); |
||
| 83 | |||
| 84 | $adapters = array(); |
||
| 85 | foreach ($inactive as $value) { |
||
| 86 | $adapters[] = array( |
||
| 87 | 'id' => $value->getId(), |
||
| 88 | 'text' => $value->getName(), |
||
| 89 | ); |
||
| 90 | } |
||
| 91 | |||
| 92 | return new Response(json_encode($adapters)); |
||
| 93 | } |
||
| 94 | |||
| 95 | return array( |
||
| 96 | 'form' => $form->createView(), |
||
| 97 | 'current' => $active->getName(), |
||
| 98 | ); |
||
| 99 | } |
||
| 100 | } |
||
| 101 |