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