| Conditions | 9 |
| Paths | 6 |
| Total Lines | 53 |
| Code Lines | 36 |
| 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 |
||
| 34 | #[IsGranted('ROLE_ADMIN')] |
||
| 35 | #[Route('/settings/search_settings', name: 'chamilo_platform_settings_search')] |
||
| 36 | public function searchSetting(Request $request): Response |
||
| 37 | { |
||
| 38 | $manager = $this->getSettingsManager(); |
||
| 39 | $formList = []; |
||
| 40 | $keyword = $request->get('keyword'); |
||
| 41 | |||
| 42 | $searchForm = $this->getSearchForm(); |
||
| 43 | $searchForm->handleRequest($request); |
||
| 44 | if ($searchForm->isSubmitted() && $searchForm->isValid()) { |
||
| 45 | $values = $searchForm->getData(); |
||
| 46 | $keyword = $values['keyword']; |
||
| 47 | } |
||
| 48 | |||
| 49 | if (empty($keyword)) { |
||
| 50 | throw $this->createNotFoundException(); |
||
| 51 | } |
||
| 52 | |||
| 53 | $settingsFromKeyword = $manager->getParametersFromKeywordOrderedByCategory($keyword); |
||
| 54 | |||
| 55 | $settings = []; |
||
| 56 | if (!empty($settingsFromKeyword)) { |
||
| 57 | foreach ($settingsFromKeyword as $category => $parameterList) { |
||
| 58 | $list = []; |
||
| 59 | foreach ($parameterList as $parameter) { |
||
| 60 | $list[] = $parameter->getVariable(); |
||
| 61 | } |
||
| 62 | $settings = $manager->load($category, null); |
||
| 63 | $schemaAlias = $manager->convertNameSpaceToService($category); |
||
| 64 | $form = $this->getSettingsFormFactory()->create($schemaAlias); |
||
| 65 | |||
| 66 | foreach (array_keys($settings->getParameters()) as $name) { |
||
| 67 | if (!\in_array($name, $list, true)) { |
||
| 68 | $form->remove($name); |
||
| 69 | $settings->remove($name); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | $form->setData($settings); |
||
| 73 | $formList[$category] = $form->createView(); |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 77 | $schemas = $manager->getSchemas(); |
||
| 78 | |||
| 79 | return $this->render( |
||
| 80 | '@ChamiloCore/Admin/Settings/search.html.twig', |
||
| 81 | [ |
||
| 82 | 'keyword' => $keyword, |
||
| 83 | 'schemas' => $schemas, |
||
| 84 | 'settings' => $settings, |
||
| 85 | 'form_list' => $formList, |
||
| 86 | 'search_form' => $searchForm->createView(), |
||
| 87 | ] |
||
| 201 |