| Conditions | 18 |
| Paths | 193 |
| Total Lines | 92 |
| Code Lines | 57 |
| 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 |
||
| 38 | public function import(Reader $reader, DateTime $start, DateTime $end, bool $suppressNotifications): ImportResult { |
||
| 39 | $start->setTime(0,0,0); |
||
| 40 | $end->setTime(0,0,0); |
||
| 41 | |||
| 42 | $data = new SubstitutionsData(); |
||
| 43 | $data->setSuppressNotifications($suppressNotifications); |
||
| 44 | $substitutions = [ ]; |
||
| 45 | |||
| 46 | $subjectOverrideMap = $this->getSubjectOverridesMap(); |
||
| 47 | $gpuSubstitutions = $this->gpuReader->readGpu($reader); |
||
| 48 | |||
| 49 | $gpuSubstitutions = array_filter($gpuSubstitutions, function(Substitution $substitution) use ($start, $end) { |
||
| 50 | if($substitution->getDate() < $start || $substitution->getDate() > $end) { |
||
| 51 | return false; |
||
| 52 | } |
||
| 53 | |||
| 54 | if($substitution->getId() === 0) { |
||
| 55 | return false; |
||
| 56 | } |
||
| 57 | |||
| 58 | return true; |
||
| 59 | }); |
||
| 60 | |||
| 61 | usort($gpuSubstitutions, [ $this, 'sort' ]); |
||
| 62 | |||
| 63 | for($idx = 0; $idx < count($gpuSubstitutions); $idx++) { |
||
| 64 | $substitution = $gpuSubstitutions[$idx]; |
||
| 65 | |||
| 66 | $includeNextLesson = false; |
||
| 67 | |||
| 68 | if($this->settings->isSubstitutionCollapsingEnabled() && $idx+1 < count($gpuSubstitutions)) { |
||
| 69 | $includeNextLesson = $this->isSubstitutionOfNextLesson($substitution, $gpuSubstitutions[$idx + 1]); |
||
| 70 | } |
||
| 71 | |||
| 72 | $substitutionData = (new SubstitutionData()) |
||
| 73 | ->setId((string)$substitution->getId()) |
||
| 74 | ->setDate($substitution->getDate()) |
||
| 75 | ->setLessonStart($substitution->getLesson()) |
||
| 76 | ->setLessonEnd($substitution->getLesson() + ($includeNextLesson ? 1 : 0)) |
||
| 77 | ->setRooms($substitution->getRooms()) |
||
| 78 | ->setReplacementRooms($substitution->getReplacementRooms()) |
||
| 79 | ->setGrades($substitution->getGrades()) |
||
| 80 | ->setReplacementGrades($substitution->getReplacementGrades()) |
||
| 81 | ->setText($substitution->getRemark()) |
||
| 82 | ->setType($this->getType($substitution)); |
||
| 83 | |||
| 84 | if($substitution->getTeacher() !== null) { |
||
| 85 | $substitutionData->setTeachers([$substitution->getTeacher()]); |
||
| 86 | } else { |
||
| 87 | $substitutionData->setTeachers([]); |
||
| 88 | } |
||
| 89 | |||
| 90 | if($substitution->getReplacementTeacher() !== null) { |
||
| 91 | $substitutionData->setReplacementTeachers([$substitution->getReplacementTeacher()]); |
||
| 92 | } else { |
||
| 93 | $substitutionData->setReplacementTeachers([]); |
||
| 94 | } |
||
| 95 | |||
| 96 | if(!empty($substitution->getSubject()) && array_key_exists($substitution->getSubject(), $subjectOverrideMap)) { |
||
| 97 | $substitutionData->setSubject($subjectOverrideMap[$substitution->getSubject()]); |
||
| 98 | } else { |
||
| 99 | $substitutionData->setSubject($substitution->getSubject()); |
||
| 100 | } |
||
| 101 | |||
| 102 | if(!empty($substitution->getReplacementSubject()) && array_key_exists($substitution->getReplacementSubject(), $subjectOverrideMap)) { |
||
| 103 | $substitutionData->setReplacementSubject($subjectOverrideMap[$substitution->getReplacementSubject()]); |
||
| 104 | } else { |
||
| 105 | $substitutionData->setReplacementSubject($substitution->getReplacementSubject()); |
||
| 106 | } |
||
| 107 | |||
| 108 | if(!empty($substitution->getSubject()) && empty($substitution->getReplacementSubject())) { |
||
| 109 | $substitutionData->setReplacementSubject($substitutionData->getSubject()); |
||
| 110 | } |
||
| 111 | |||
| 112 | $substitutionData->setStartsBefore($substitutionData->getType() === 'Pausenaufsichtsvertretung'); |
||
| 113 | |||
| 114 | if($this->matchesFlag($substitution->getFlags(), SubstitutionFlag::DoNotPrintFlag)) { |
||
| 115 | continue; |
||
| 116 | } |
||
| 117 | |||
| 118 | $substitutions[] = $substitutionData; |
||
| 119 | |||
| 120 | if($includeNextLesson) { |
||
| 121 | // Skip next substitution as it is already handled. |
||
| 122 | $idx++; |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | $data->setSubstitutions($substitutions); |
||
| 127 | |||
| 128 | $result = $this->importer->import($data, $this->strategy); |
||
| 129 | return $result; |
||
| 130 | } |
||
| 209 | } |
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