| Conditions | 13 |
| Paths | 14 |
| Total Lines | 83 |
| Code Lines | 58 |
| 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 |
||
| 45 | #[IsGranted('ROLE_ADMIN')] |
||
| 46 | #[Route('/settings/search_settings', name: 'chamilo_platform_settings_search')] |
||
| 47 | public function searchSetting(Request $request, AccessUrlHelper $accessUrlHelper): Response |
||
| 48 | { |
||
| 49 | $manager = $this->getSettingsManager(); |
||
| 50 | |||
| 51 | $url = $accessUrlHelper->getCurrent(); |
||
| 52 | $manager->setUrl($url); |
||
| 53 | |||
| 54 | $formList = []; |
||
| 55 | $templateMap = []; |
||
| 56 | $templateMapByCategory = []; |
||
| 57 | $settings = []; |
||
| 58 | |||
| 59 | $keyword = trim((string) $request->query->get('keyword', '')); |
||
| 60 | |||
| 61 | $searchForm = $this->getSearchForm(); |
||
| 62 | $searchForm->handleRequest($request); |
||
| 63 | if ($searchForm->isSubmitted() && $searchForm->isValid()) { |
||
| 64 | $values = $searchForm->getData(); |
||
| 65 | $keyword = trim((string) ($values['keyword'] ?? '')); |
||
| 66 | } |
||
| 67 | |||
| 68 | $schemas = $manager->getSchemas(); |
||
| 69 | |||
| 70 | if ($keyword === '') { |
||
| 71 | return $this->render('@ChamiloCore/Admin/Settings/search.html.twig', [ |
||
| 72 | 'keyword' => $keyword, |
||
| 73 | 'schemas' => $schemas, |
||
| 74 | 'settings' => $settings, |
||
| 75 | 'form_list' => $formList, |
||
| 76 | 'search_form' => $searchForm->createView(), |
||
| 77 | 'template_map' => $templateMap, |
||
| 78 | 'template_map_by_category' => $templateMapByCategory, |
||
| 79 | ]); |
||
| 80 | } |
||
| 81 | |||
| 82 | $settingsRepo = $this->entityManager->getRepository(SettingsCurrent::class); |
||
| 83 | $settingsWithTemplate = $settingsRepo->findBy(['url' => $url]); |
||
| 84 | foreach ($settingsWithTemplate as $s) { |
||
| 85 | if ($s->getValueTemplate()) { |
||
| 86 | $templateMap[$s->getVariable()] = $s->getValueTemplate()->getId(); |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | $settingsFromKeyword = $manager->getParametersFromKeywordOrderedByCategory($keyword); |
||
| 91 | if (!empty($settingsFromKeyword)) { |
||
| 92 | foreach ($settingsFromKeyword as $category => $parameterList) { |
||
| 93 | if (empty($category)) { |
||
| 94 | continue; |
||
| 95 | } |
||
| 96 | |||
| 97 | $variablesInCategory = []; |
||
| 98 | foreach ($parameterList as $parameter) { |
||
| 99 | $var = $parameter->getVariable(); |
||
| 100 | $variablesInCategory[] = $var; |
||
| 101 | if (isset($templateMap[$var])) { |
||
| 102 | $templateMapByCategory[$category][$var] = $templateMap[$var]; |
||
| 103 | } |
||
| 104 | } |
||
| 105 | $settings = $manager->load($category); |
||
| 106 | $schemaAlias = $manager->convertNameSpaceToService($category); |
||
| 107 | $form = $this->getSettingsFormFactory()->create($schemaAlias); |
||
| 108 | |||
| 109 | foreach (array_keys($settings->getParameters()) as $name) { |
||
| 110 | if (!in_array($name, $variablesInCategory, true)) { |
||
| 111 | $form->remove($name); |
||
| 112 | $settings->remove($name); |
||
| 113 | } |
||
| 114 | } |
||
| 115 | $form->setData($settings); |
||
| 116 | $formList[$category] = $form->createView(); |
||
| 117 | } |
||
| 118 | } |
||
| 119 | |||
| 120 | return $this->render('@ChamiloCore/Admin/Settings/search.html.twig', [ |
||
| 121 | 'keyword' => $keyword, |
||
| 122 | 'schemas' => $schemas, |
||
| 123 | 'settings' => $settings, |
||
| 124 | 'form_list' => $formList, |
||
| 125 | 'search_form' => $searchForm->createView(), |
||
| 126 | 'template_map' => $templateMap, |
||
| 127 | 'template_map_by_category' => $templateMapByCategory, |
||
| 128 | ]); |
||
| 249 |