| Conditions | 6 |
| Paths | 14 |
| Total Lines | 54 |
| Code Lines | 32 |
| 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 |
||
| 22 | public function onRow(Row $row) |
||
| 23 | { |
||
| 24 | $index = $row->getIndex(); |
||
| 25 | $row = $row->toArray(); |
||
| 26 | |||
| 27 | $student = Student::whereNumber($row['student_id']) |
||
| 28 | ->firstOrNew(['student_number' => strtolower($row['student_id'])]); |
||
| 29 | |||
| 30 | if (! $student->exists) { |
||
| 31 | /** @var \App\Judite\Models\User $user */ |
||
| 32 | $user = User::make([ |
||
| 33 | 'name' => $row['student_name'] ?? $row['student_id'], |
||
| 34 | 'email' => strtolower($row['student_email'] ?? $row['student_id'].'@alunos.uminho.pt'), |
||
| 35 | 'password' => bcrypt(Str::random(8)), |
||
| 36 | ]); |
||
| 37 | $user->verification_token = Str::random(32); |
||
| 38 | $user->save(); |
||
| 39 | $student = $user->student()->save($student); |
||
| 40 | } |
||
| 41 | |||
| 42 | // Check if the given course id exists |
||
| 43 | $course = Course::whereCode($row['course_id'])->first(); |
||
| 44 | if ($course === null) { |
||
| 45 | $exception = new InvalidFieldValueException(); |
||
| 46 | $exception->setField('Course ID', $row['course_id'], "The course {$row['course_id']} does not exist. (at line {$index})"); |
||
| 47 | throw $exception; |
||
| 48 | } |
||
| 49 | |||
| 50 | // Check if the enrollment exists |
||
| 51 | $enrollment = Enrollment::where([ |
||
| 52 | 'course_id' => $course->id, |
||
| 53 | 'student_id' => $student->id, |
||
| 54 | ])->first(); |
||
| 55 | |||
| 56 | if ($enrollment === null) { |
||
| 57 | $enrollment = $student->enroll($course); |
||
| 58 | } |
||
| 59 | |||
| 60 | // Check if the given shift tag exists in the associated course |
||
| 61 | if ($row['shift'] !== null) { |
||
| 62 | $shift = $course->getShiftByTag($row['shift']); |
||
| 63 | |||
| 64 | if ($shift === null) { |
||
| 65 | $shift = Shift::make(['tag' => $row['shift']]); |
||
|
|
|||
| 66 | $course->addShift($shift); |
||
| 67 | } |
||
| 68 | |||
| 69 | $enrollment->shift()->associate($shift); |
||
| 70 | } else { |
||
| 71 | $enrollment->shift()->dissociate(); |
||
| 72 | } |
||
| 73 | |||
| 74 | // Add the shift to the enrollment |
||
| 75 | $enrollment->save(); |
||
| 76 | } |
||
| 78 |
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