| Conditions | 6 |
| Paths | 6 |
| Total Lines | 144 |
| Code Lines | 111 |
| 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 |
||
| 54 | #[Route(path: '/settings', name: 'import_untis_settings')] |
||
| 55 | public function settings(UntisSettings $settings, Request $request, DateReader $reader, EnumStringConverter $enumStringConverter, StudentIdGenerator $studentIdGenerator): Response { |
||
| 56 | $form = $this->createFormBuilder() |
||
| 57 | ->add('overrides', CollectionType::class, [ |
||
| 58 | 'entry_type' => SubjectOverrideType::class, |
||
| 59 | 'allow_add' => true, |
||
| 60 | 'allow_delete' => true, |
||
| 61 | 'by_reference' => false, |
||
| 62 | 'data' => $settings->getSubjectOverrides() |
||
| 63 | ]) |
||
| 64 | ->add('weeks', CollectionType::class, [ |
||
| 65 | 'entry_type' => CalendarWeekSchoolWeekType::class, |
||
| 66 | 'allow_add' => true, |
||
| 67 | 'allow_delete' => true, |
||
| 68 | 'by_reference' => false, |
||
| 69 | 'data' => $settings->getWeekMap() |
||
| 70 | ]) |
||
| 71 | ->add('import_weeks', FileType::class, [ |
||
| 72 | 'label' => 'dates.txt', |
||
| 73 | 'required' => false |
||
| 74 | ]) |
||
| 75 | ->add('substitution_days', IntegerType::class, [ |
||
| 76 | 'label' => 'import.settings.substitutions.days.label', |
||
| 77 | 'help' => 'import.settings.substitutions.days.help', |
||
| 78 | 'data' => $settings->getSubstitutionDays() |
||
| 79 | ]) |
||
| 80 | ->add('collapse_substitutions', CheckboxType::class, [ |
||
| 81 | 'label' => 'import.settings.substitutions.collapse.label', |
||
| 82 | 'help' => 'import.settings.substitutions.collapse.help', |
||
| 83 | 'required' => false, |
||
| 84 | 'label_attr' => [ |
||
| 85 | 'class' => 'checkbox-custom' |
||
| 86 | ], |
||
| 87 | 'data' => $settings->isSubstitutionCollapsingEnabled() |
||
| 88 | ]) |
||
| 89 | ->add('exam_writers', CheckboxType::class, [ |
||
| 90 | 'label' => 'import.settings.exams.include_students.label', |
||
| 91 | 'help' => 'import.settings.exams.include_students.help', |
||
| 92 | 'required' => false, |
||
| 93 | 'label_attr' => [ |
||
| 94 | 'class' => 'checkbox-custom' |
||
| 95 | ], |
||
| 96 | 'data' => $settings->alwaysImportExamWriters() |
||
| 97 | ]) |
||
| 98 | ->add('ignore_options_regexp', RegExpType::class, [ |
||
| 99 | 'label' => 'import.settings.exams.ignore_options_regexp.label', |
||
| 100 | 'help' => 'import.settings.exams.ignore_options_regexp.help', |
||
| 101 | 'required' => false, |
||
| 102 | 'data' => $settings->getIgnoreStudentOptionRegExp() |
||
| 103 | ]) |
||
| 104 | ->add('student_id_format', EnumType::class, [ |
||
| 105 | 'label' => 'import.settings.students.format.label', |
||
| 106 | 'help' => 'import.settings.students.format.help', |
||
| 107 | 'class' => StudentIdFormat::class, |
||
| 108 | 'choice_label' => function(StudentIdFormat $format) use($enumStringConverter) { |
||
| 109 | return $enumStringConverter->convert($format); |
||
| 110 | }, |
||
| 111 | 'data' => $settings->getStudentIdentifierFormat() |
||
| 112 | ]) |
||
| 113 | ->add('student_id_firstname_letters', IntegerType::class, [ |
||
| 114 | 'label' => 'import.settings.students.firstname_letters.label', |
||
| 115 | 'help' => 'import.settings.students.firstname_letters.help', |
||
| 116 | 'required' => false, |
||
| 117 | 'constraints' => [ |
||
| 118 | new GreaterThanOrEqual(0) |
||
| 119 | ], |
||
| 120 | 'data' => $settings->getStudentIdentifierNumberOfLettersOfFirstname() |
||
| 121 | ]) |
||
| 122 | ->add('student_id_lastname_letters', IntegerType::class, [ |
||
| 123 | 'label' => 'import.settings.students.lastname_letters.label', |
||
| 124 | 'help' => 'import.settings.students.lastname_letters.help', |
||
| 125 | 'required' => false, |
||
| 126 | 'constraints' => [ |
||
| 127 | new GreaterThanOrEqual(0) |
||
| 128 | ], |
||
| 129 | 'data' => $settings->getStudentIdentifierNumberOfLettersOfLastname() |
||
| 130 | ]) |
||
| 131 | ->add('student_id_birthday_format', TextType::class, [ |
||
| 132 | 'label' => 'import.settings.students.birthday_format.label', |
||
| 133 | 'help' => 'import.settings.students.birthday_format.help', |
||
| 134 | 'required' => false, |
||
| 135 | 'constraints' => [ |
||
| 136 | new NotBlank(allowNull: true) |
||
| 137 | ], |
||
| 138 | 'data' => $settings->getStudentIdentifierBirthdayFormat() |
||
| 139 | ]) |
||
| 140 | ->add('student_id_separator', TextType::class, [ |
||
| 141 | 'label' => 'import.settings.students.separator.label', |
||
| 142 | 'help' => 'import.settings.students.separator.help', |
||
| 143 | 'required' => false, |
||
| 144 | 'constraints' => [ |
||
| 145 | new NotBlank(allowNull: true) |
||
| 146 | ], |
||
| 147 | 'data' => $settings->getStudentIdentifierSeparator() |
||
| 148 | ]) |
||
| 149 | ->getForm(); |
||
| 150 | $form->handleRequest($request); |
||
| 151 | |||
| 152 | if($form->isSubmitted() && $form->isValid()) { |
||
| 153 | $settings->setSubjectOverrides($form->get('overrides')->getData()); |
||
| 154 | $settings->setWeekMap($form->get('weeks')->getData()); |
||
| 155 | $settings->setSubstitutionDays($form->get('substitution_days')->getData()); |
||
| 156 | $settings->setSubstitutionCollapsingEnabled($form->get('collapse_substitutions')->getData()); |
||
| 157 | $settings->setAlwaysImportExamWriters($form->get('exam_writers')->getData()); |
||
| 158 | $settings->setIgnoreStudentOptionRegExp($form->get('ignore_options_regexp')->getData()); |
||
| 159 | $settings->setStudentIdentifierFormat($form->get('student_id_format')->getData()); |
||
| 160 | $settings->setStudentIdentifierNumberOfLettersOfFirstname($form->get('student_id_firstname_letters')->getData()); |
||
| 161 | $settings->setStudentIdentifierNumberOfLettersOfLastname($form->get('student_id_lastname_letters')->getData()); |
||
| 162 | $settings->setStudentIdentifierBirthdayFormat($form->get('student_id_birthday_format')->getData()); |
||
| 163 | $settings->setStudentIdentifierSeparator($form->get('student_id_separator')->getData()); |
||
| 164 | |||
| 165 | /** @var UploadedFile|null $file */ |
||
| 166 | $file = $form->get('import_weeks')->getData(); |
||
| 167 | if($file !== null) { |
||
| 168 | try { |
||
| 169 | $dates = $reader->readDatabase(Reader::createFromPath($file->getRealPath())); |
||
| 170 | $map = []; |
||
| 171 | |||
| 172 | foreach ($dates as $date) { |
||
| 173 | $map[] = [ |
||
| 174 | 'calendar_week' => $date->getCalendarWeek(), |
||
| 175 | 'school_week' => $date->getSchoolWeek() |
||
| 176 | ]; |
||
| 177 | } |
||
| 178 | $settings->setWeekMap($map); |
||
| 179 | } catch (ImportException $exception) { |
||
| 180 | $this->addFlash('error', $exception->getMessage()); |
||
| 181 | } |
||
| 182 | } |
||
| 183 | |||
| 184 | $this->addFlash('success', 'import.settings.success'); |
||
| 185 | return $this->redirectToRoute('import_untis_settings'); |
||
| 186 | } |
||
| 187 | |||
| 188 | $student = (new Student()) |
||
| 189 | ->setFirstname('Erika') |
||
| 190 | ->setLastname('Musterfrau') |
||
| 191 | ->setBirthday((new DateTime())->setTime(0,0,0)); |
||
| 192 | |||
| 193 | $preview = $studentIdGenerator->generate($student); |
||
| 194 | |||
| 195 | return $this->render('import/settings.html.twig', [ |
||
| 196 | 'form' => $form->createView(), |
||
| 197 | 'student_preview' => $preview |
||
| 198 | ]); |
||
| 438 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths