| Conditions | 4 |
| Paths | 9 |
| Total Lines | 54 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 32 | public function updateAction(Request $request, $namespace, $course) |
||
| 33 | { |
||
| 34 | $manager = $this->getSettingsManager(); |
||
| 35 | |||
| 36 | $schemaAlias = $manager->convertNameSpaceToService($namespace); |
||
| 37 | $settings = $manager->load($namespace); |
||
| 38 | |||
| 39 | $form = $this |
||
| 40 | ->getSettingsFormFactory() |
||
| 41 | ->create($schemaAlias); |
||
| 42 | |||
| 43 | $form->setData($settings); |
||
| 44 | |||
| 45 | if ($form->handleRequest($request)->isValid()) { |
||
| 46 | $messageType = 'success'; |
||
| 47 | try { |
||
| 48 | $manager->setCourse($course); |
||
| 49 | $manager->saveSettings($namespace, $form->getData()); |
||
| 50 | $message = $this->getTranslator()->trans( |
||
| 51 | 'sylius.settings.update', |
||
| 52 | [], |
||
| 53 | 'flashes' |
||
| 54 | ); |
||
| 55 | } catch (ValidatorException $exception) { |
||
| 56 | $message = $this->getTranslator()->trans( |
||
| 57 | $exception->getMessage(), |
||
| 58 | [], |
||
| 59 | 'validators' |
||
| 60 | ); |
||
| 61 | $messageType = 'error'; |
||
| 62 | } |
||
| 63 | $request->getSession()->getBag('flashes')->add( |
||
| 64 | $messageType, |
||
| 65 | $message |
||
| 66 | ); |
||
| 67 | |||
| 68 | if ($request->headers->has('referer')) { |
||
| 69 | return $this->redirect($request->headers->get('referer')); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | $schemas = $manager->getSchemas(); |
||
| 73 | |||
| 74 | return $this->render( |
||
| 75 | $request->attributes->get( |
||
| 76 | 'template', |
||
| 77 | 'ChamiloCourseBundle:Settings:update.html.twig' |
||
| 78 | ), |
||
| 79 | [ |
||
| 80 | 'course' => $course, |
||
| 81 | 'schemas' => $schemas, |
||
| 82 | 'settings' => $settings, |
||
| 83 | 'form' => $form->createView(), |
||
| 84 | 'keyword' => '', |
||
| 85 | 'search_form' => '', |
||
| 86 | ] |
||
| 120 |