Conditions | 8 |
Paths | 7 |
Total Lines | 64 |
Code Lines | 38 |
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 |
||
52 | public function execute($entity, EntityConfiguration $config, Request $request, $options = null) |
||
53 | { |
||
54 | $this->checkRequired($options, 'form'); |
||
55 | |||
56 | $id = (string) $this->getEntityId($entity, $config); |
||
57 | if (!$entity) { |
||
58 | throw new NotFoundHttpException( |
||
59 | sprintf('The translatable with %s id does not exist', $id) |
||
60 | ); |
||
61 | } |
||
62 | |||
63 | $locale = $request->query->get('locale'); |
||
64 | // if (loquesea) { |
||
|
|||
65 | // // TODO: HACER EL IF DE ARRIBA CUANDO EL LOCALE QUE NOS LLEGA NO ESTÁ DEFINIDO EN LA CONFIG |
||
66 | // throw new NotFoundHttpException( |
||
67 | // sprintf('%s locale is not supported from the admin', $locale) |
||
68 | // ); |
||
69 | // } |
||
70 | |||
71 | try { |
||
72 | $translation = $entity->{$locale}(); |
||
73 | } catch (TranslationDoesNotExistException $exception) { |
||
74 | $translation = null; |
||
75 | } |
||
76 | |||
77 | $form = $this->formHandler->createForm( |
||
78 | $options['form'], |
||
79 | $translation, [ |
||
80 | 'locale' => $locale, |
||
81 | 'page_id' => $id, |
||
82 | ]); |
||
83 | if ($request->isMethod('POST') || $request->isMethod('PUT') || $request->isMethod('PATCH')) { |
||
84 | $form->handleRequest($request); |
||
85 | if ($form->isValid() && $form->isSubmitted()) { |
||
86 | $this->commandBus->handle( |
||
87 | $form->getData() |
||
88 | ); |
||
89 | $this->session->getFlashBag()->add( |
||
90 | 'lin3s_admin_success', |
||
91 | sprintf( |
||
92 | 'The %s translation is successfully saved', |
||
93 | $config->name() |
||
94 | ) |
||
95 | ); |
||
96 | } else { |
||
97 | $this->session->getFlashBag()->add( |
||
98 | 'lin3s_admin_error', |
||
99 | sprintf( |
||
100 | 'Errors while saving %s translation. Please check all fields and try again', |
||
101 | $config->name() |
||
102 | ) |
||
103 | ); |
||
104 | } |
||
105 | } |
||
106 | |||
107 | return new Response( |
||
108 | $this->twig->render('@Lin3sCmsAdminBridge/Admin/edit_translation.html.twig', [ |
||
109 | 'entity' => $entity, |
||
110 | 'entityConfig' => $config, |
||
111 | 'locale' => $locale, |
||
112 | 'form' => $form->createView(), |
||
113 | ]) |
||
114 | ); |
||
115 | } |
||
116 | |||
128 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.