| Conditions | 5 |
| Paths | 18 |
| Total Lines | 72 |
| Code Lines | 59 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 15 | ||
| Bugs | 2 | Features | 4 |
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 |
||
| 75 | public function process($student) |
||
| 76 | { |
||
| 77 | try{ |
||
| 78 | $wrongStudentsClass = Institution_class_student::where('institution_id', $student['institution_id']) |
||
| 79 | ->whereRaw('institution_class_id not in (select id from institution_classes where institution_id ='.$student['institution_id'].' )') |
||
| 80 | ->orWhere('institution_class_id', 0) |
||
| 81 | ->where('student_id', $student['student_id']) |
||
| 82 | ->get()->toArray(); |
||
| 83 | |||
| 84 | if (count($wrongStudentsClass) > 0) { |
||
| 85 | Institution_class_student::where('student_id', $student['student_id'])->forceDelete(); |
||
| 86 | Institution_student_admission::where('student_id', $student['student_id'])->forceDelete(); |
||
| 87 | Institution_student::where('student_id', $student['student_id'])->forceDelete(); |
||
| 88 | |||
| 89 | array_walk($wrongStudentsClass, array($this->class, 'updateClassCount')); |
||
| 90 | |||
| 91 | $institutionClass = Institution_class::getGradeClasses($student['education_grade_id'], $student['institution_id']); |
||
| 92 | |||
| 93 | if (count($institutionClass) == 1) { |
||
| 94 | $start_date = new Carbon($student['start_date']); |
||
| 95 | $end_date = new Carbon($student['end_date']); |
||
| 96 | Institution_student_admission::create( |
||
| 97 | [ |
||
| 98 | 'student_id' => $student['student_id'], |
||
| 99 | 'institution_class_id' => $institutionClass[0]['id'], |
||
| 100 | 'start_date' => $student['start_date'], |
||
| 101 | 'start_year' => $start_date->format('Y'), |
||
| 102 | 'end_date' => $student['start_date'], |
||
| 103 | 'end_year' => $end_date->format('Y'), |
||
| 104 | 'education_grade_id' => $student['education_grade_id'], |
||
| 105 | 'institution_id' => $student['institution_id'], |
||
| 106 | 'status_id' => 124, |
||
| 107 | 'academic_period_id' => $student['academic_period_id'], |
||
| 108 | 'created_user_id' => $student['created_user_id'], |
||
| 109 | 'updated_from' => $student['updated_from'] |
||
| 110 | ] |
||
| 111 | ); |
||
| 112 | $institutionClassStudent = [ |
||
| 113 | 'student_id' => $student['student_id'], |
||
| 114 | 'institution_class_id' => $institutionClass[0]['id'], |
||
| 115 | 'education_grade_id' => $student['education_grade_id'], |
||
| 116 | 'institution_id' => $student['institution_id'], |
||
| 117 | 'status_id' => 124, |
||
| 118 | 'academic_period_id' => $student['academic_period_id'], |
||
| 119 | 'student_status_id' => 1, |
||
| 120 | 'created_user_id' => $student['created_user_id'], |
||
| 121 | 'updated_from' => $student['updated_from'] |
||
| 122 | ]; |
||
| 123 | Institution_class_student::create($institutionClassStudent); |
||
| 124 | Institution_student::create([ |
||
| 125 | 'student_id' => $student['student_id'], |
||
| 126 | 'student_status_id' => 1, |
||
| 127 | 'education_grade_id' => $student['education_grade_id'], |
||
| 128 | 'institution_id' => $student['institution_id'], |
||
| 129 | 'academic_period_id' => $student['academic_period_id'], |
||
| 130 | 'created_user_id' => $student['created_user_id'], |
||
| 131 | 'start_date' => $student['start_date'], |
||
| 132 | 'start_year' => $start_date->format('Y'), |
||
| 133 | 'end_date' => $student['start_date'], |
||
| 134 | 'end_year' => $end_date->format('Y'), |
||
| 135 | 'taking_g5_exam' => $student['updated_from'] == 'doe' ? true : false, |
||
| 136 | 'income_at_g5' => $student['income_at_g5'], |
||
| 137 | 'updated_from' => $student['updated_from'], |
||
| 138 | 'exam_center_for_special_education_g5' => $student['exam_center_for_special_education_g5'], |
||
| 139 | 'modified_user_id' => $student['modified_user_id'], |
||
| 140 | ]); |
||
| 141 | $institutionClassStudent = [$institutionClassStudent]; |
||
| 142 | array_walk($institutionClassStudent, array($this->class, 'updateClassCount')); |
||
| 143 | } |
||
| 144 | } |
||
| 145 | }catch(\Exception $e){ |
||
| 146 | dd($e); |
||
| 147 | } |
||
| 150 |