| Conditions | 28 |
| Paths | 4800 |
| Total Lines | 153 |
| Code Lines | 96 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 44 | private function export(Book $book, array $students, ?TuitionEntity $tuition, ?GradeEntity $grade, SectionEntity $section, EntryOverview $overview): Book { |
||
| 45 | $book |
||
| 46 | ->setStart($section->getStart()) |
||
|
|
|||
| 47 | ->setEnd($section->getEnd()) |
||
| 48 | ->setSection($this->castSection($section)); |
||
| 49 | |||
| 50 | if($book->getTuition() !== null && $tuition !== null) { |
||
| 51 | /** @var TeacherEntity $teacher */ |
||
| 52 | foreach ($tuition->getTeachers() as $teacher) { |
||
| 53 | $book->getTuition()->addTeacher( |
||
| 54 | (new Teacher()) |
||
| 55 | ->setAcronym($teacher->getAcronym()) |
||
| 56 | ->setId($teacher->getUuid()->toString()) |
||
| 57 | ->setFirstname($teacher->getFirstname()) |
||
| 58 | ->setLastname($teacher->getLastname()) |
||
| 59 | ->setTitle($teacher->getTitle()) |
||
| 60 | ); |
||
| 61 | } |
||
| 62 | } |
||
| 63 | |||
| 64 | if($tuition !== null) { |
||
| 65 | $grades = []; |
||
| 66 | |||
| 67 | foreach ($tuition->getStudyGroup()->getGrades() as $tuitionGrade) { |
||
| 68 | $exportGrade = (new Grade()) |
||
| 69 | ->setName($tuitionGrade->getName()); |
||
| 70 | |||
| 71 | /** @var GradeTeacher $teacher */ |
||
| 72 | foreach ($tuitionGrade->getTeachers() as $teacher) { |
||
| 73 | $exportGrade->addTeacher( |
||
| 74 | (new Teacher()) |
||
| 75 | ->setAcronym($teacher->getTeacher()->getAcronym()) |
||
| 76 | ->setId($teacher->getTeacher()->getUuid()->toString()) |
||
| 77 | ->setFirstname($teacher->getTeacher()->getFirstname()) |
||
| 78 | ->setLastname($teacher->getTeacher()->getLastname()) |
||
| 79 | ->setTitle($teacher->getTeacher()->getTitle()) |
||
| 80 | ); |
||
| 81 | } |
||
| 82 | |||
| 83 | $grades[] = $exportGrade; |
||
| 84 | } |
||
| 85 | $book->setGrades($grades); |
||
| 86 | } |
||
| 87 | |||
| 88 | $gradeOverview = null; |
||
| 89 | $tuitions = [ ]; |
||
| 90 | |||
| 91 | if($tuition !== null) { |
||
| 92 | $tuitions = [ $tuition ]; |
||
| 93 | $gradeOverview = $this->gradeOverviewHelper->computeOverviewForTuition($tuition); |
||
| 94 | } else if($grade !== null) { |
||
| 95 | $gradeOverview = $this->gradeOverviewHelper->computeForGrade($grade, $section); |
||
| 96 | foreach($gradeOverview->getCategories() as $category) { |
||
| 97 | $tuitions[$category->getTuition()->getId()] = $category->getTuition(); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | if($gradeOverview !== null) { |
||
| 102 | foreach($tuitions as $gradeTuition) { |
||
| 103 | $studentGrades = new StudentGrades(); |
||
| 104 | $studentGrades->setTuition($this->castTuition($gradeTuition)); |
||
| 105 | |||
| 106 | foreach ($gradeOverview->getCategories() as $category) { |
||
| 107 | if($category->getTuition() !== $gradeTuition) { |
||
| 108 | continue; |
||
| 109 | } |
||
| 110 | |||
| 111 | if ($category->getCategory()->isExportable()) { |
||
| 112 | $studentGrades->addCategory( |
||
| 113 | (new TuitionGradeCategory()) |
||
| 114 | ->setUuid($category->getCategory()->getUuid()->toString()) |
||
| 115 | ->setDisplayName($category->getCategory()->getDisplayName()) |
||
| 116 | ); |
||
| 117 | } |
||
| 118 | } |
||
| 119 | |||
| 120 | foreach ($gradeOverview->getRows() as $row) { |
||
| 121 | foreach ($gradeOverview->getCategories() as $category) { |
||
| 122 | if($category->getTuition() !== $gradeTuition) { |
||
| 123 | continue; |
||
| 124 | } |
||
| 125 | |||
| 126 | if ($category->getCategory()->isExportable()) { |
||
| 127 | $studentGrades->addGrade((new TuitionGrade()) |
||
| 128 | ->setStudent($row->getTuitionOrStudent()->getExternalId()) |
||
| 129 | ->setGradeCategory($category->getCategory()->getUuid()->toString()) |
||
| 130 | ->setEncryptedGrade($row->getGrade($category->getTuition(), $category->getCategory())?->getEncryptedGrade())); |
||
| 131 | } |
||
| 132 | } |
||
| 133 | } |
||
| 134 | |||
| 135 | $book->addStudentGrades($studentGrades); |
||
| 136 | } |
||
| 137 | } |
||
| 138 | |||
| 139 | $this->sorter->sort($students, StudentStrategy::class); |
||
| 140 | |||
| 141 | $studentInfo = [ ]; |
||
| 142 | $tuitionsToConsider = $tuition !== null ? [ $tuition ] : $this->tuitionRepository->findAllByGrades([$grade], $section); |
||
| 143 | |||
| 144 | foreach($students as $student) { |
||
| 145 | $info = $this->studentInfoResolver->resolveStudentInfo($student, $section, $tuitionsToConsider); |
||
| 146 | $studentInfo[$student->getId()] = $info; |
||
| 147 | $book->addStudentSummary( |
||
| 148 | (new StudentSummary()) |
||
| 149 | ->setStudent($this->castStudent($student, $section)) |
||
| 150 | ->setLateMinutesCount($info->getLateMinutesCount()) |
||
| 151 | ->setAbsentLessonsCount($info->getAbsentLessonsCount()) |
||
| 152 | ->setExcuseStatusNotSetLessonCount($info->getNotExcusedOrNotSetLessonsCount()) |
||
| 153 | ->setNotExcusedAbsentLessonCount($info->getNotExcusedAbsentLessonsCount()) |
||
| 154 | ); |
||
| 155 | } |
||
| 156 | |||
| 157 | $weeks = [ ]; |
||
| 158 | foreach($overview->getDays() as $day) { |
||
| 159 | $weekNumber = (int)$day->getDate()->format('W'); |
||
| 160 | |||
| 161 | if(!isset($weeks[$weekNumber])) { |
||
| 162 | $weeks[$weekNumber] = (new Week()) |
||
| 163 | ->setStart(clone $day->getDate()) |
||
| 164 | ->setEnd((clone $day->getDate())->modify('+6 days')) |
||
| 165 | ->setWeekNumber($weekNumber); |
||
| 166 | } |
||
| 167 | |||
| 168 | $exportDay = (new Day()) |
||
| 169 | ->setDate(clone $day->getDate()); |
||
| 170 | |||
| 171 | foreach($overview->getComments($day->getDate()) as $comment) { |
||
| 172 | $exportDay->addComment($this->castComment($comment, $section)); |
||
| 173 | } |
||
| 174 | |||
| 175 | $lessons = [ ]; |
||
| 176 | |||
| 177 | foreach($day->getLessons() as $lesson) { |
||
| 178 | if($lesson->getEntry() === null) { |
||
| 179 | $lessons[] = $this->castLesson($lesson->getLesson(), $lesson->getLessonNumber()); |
||
| 180 | } else { |
||
| 181 | $lessons[$lesson->getEntry()->getUuid()->toString()] = $this->castEntry($lesson->getEntry(), $section, $studentInfo); |
||
| 182 | } |
||
| 183 | } |
||
| 184 | |||
| 185 | foreach($lessons as $lesson) { |
||
| 186 | $exportDay->addLesson($lesson); |
||
| 187 | } |
||
| 188 | |||
| 189 | $weeks[$weekNumber]->addDay($exportDay); |
||
| 190 | } |
||
| 191 | |||
| 192 | foreach($weeks as $week) { |
||
| 193 | $book->addWeek($week); |
||
| 194 | } |
||
| 195 | |||
| 196 | return $book; |
||
| 197 | } |
||
| 386 | } |