Total Complexity | 41 |
Total Lines | 258 |
Duplicated Lines | 0 % |
Changes | 6 | ||
Bugs | 3 | Features | 0 |
Complex classes like Institution_student often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Institution_student, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
12 | class Institution_student extends Base_Model |
||
13 | { |
||
14 | |||
15 | use SoftDeletes; |
||
16 | |||
17 | public const CREATED_AT = 'created'; |
||
18 | public const UPDATED_AT = 'modified'; |
||
19 | |||
20 | /** |
||
21 | * The database table used by the model. |
||
22 | * |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $table = 'institution_students'; |
||
26 | |||
27 | protected $softDelete = true; |
||
28 | |||
29 | |||
30 | /** |
||
31 | * @var bool |
||
32 | */ |
||
33 | public $timestamps = true; |
||
34 | |||
35 | /** |
||
36 | * Attributes that should be mass-assignable. |
||
37 | * |
||
38 | * @var array |
||
39 | */ |
||
40 | protected $fillable = ['student_status_id', 'student_id', 'education_grade_id', 'academic_period_id', 'start_date', 'start_year', 'end_date', 'end_year', 'institution_id', 'previous_institution_student_id', 'modified_user_id', 'modified', 'created_user_id', 'created', 'area_administrative_id', 'admission_id']; |
||
41 | |||
42 | /** |
||
43 | * The attributes excluded from the model's JSON form. |
||
44 | * |
||
45 | * @var array |
||
46 | */ |
||
47 | protected $hidden = []; |
||
48 | |||
49 | /** |
||
50 | * The attributes that should be casted to native types. |
||
51 | * |
||
52 | * @var array |
||
53 | */ |
||
54 | protected $casts = []; |
||
55 | |||
56 | protected $maps = [ |
||
57 | 'uuid' => 'id' |
||
58 | ]; |
||
59 | |||
60 | /** |
||
61 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
62 | */ |
||
63 | public function institutionStudents() |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * |
||
70 | */ |
||
71 | public static function boot() |
||
72 | { |
||
73 | parent::boot(); |
||
74 | self::creating(function ($model) { |
||
75 | $model->id = (string) Uuid::generate(4); |
||
76 | $model->created = now(); |
||
77 | }); |
||
78 | } |
||
79 | |||
80 | |||
81 | /** |
||
82 | * @var string |
||
83 | */ |
||
84 | protected $primaryKey = 'id'; |
||
85 | protected $keyType = 'string'; |
||
86 | |||
87 | /** |
||
88 | * @param $inputs |
||
89 | * @return bool |
||
90 | * |
||
91 | * |
||
92 | */ |
||
93 | public static function isDuplicated($inputs) |
||
100 | } |
||
101 | |||
102 | |||
103 | /** |
||
104 | * The attributes that should be mutated to dates. |
||
105 | * |
||
106 | * @var array |
||
107 | */ |
||
108 | protected $dates = ['date_of_birth', 'date_of_death', 'last_login', 'modified', 'created', 'start_date', 'end_date', 'modified', 'created']; |
||
109 | |||
110 | /** |
||
111 | * get list of students which are going to be promoted |
||
112 | * |
||
113 | * @param $institutionGrade |
||
114 | * @param $academicPeriod |
||
115 | * @return array |
||
116 | */ |
||
117 | public function getStudentListToPromote($institutionGrade, $academicPeriod) |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * Create new Institution student from examination data |
||
140 | * |
||
141 | * @param [type] $student |
||
142 | * @param [type] $admissionInfo |
||
143 | * @return void |
||
144 | */ |
||
145 | public static function createExaminationData($student, $admissionInfo) |
||
176 | } |
||
177 | } |
||
178 | |||
179 | /** |
||
180 | * Update new Institution student from examination data |
||
181 | * |
||
182 | * @param [type] $student |
||
183 | * @param [type] $admissionInfo |
||
184 | * @return void |
||
185 | */ |
||
186 | public static function updateExaminationData($student, $admissionInfo) |
||
187 | { |
||
188 | $student['sp_center'] = gettype((int)$student['sp_center']) == 'integer' ? $student['sp_center'] : 0; |
||
189 | try { |
||
190 | self::where([ |
||
191 | 'student_id' => $student['student_id'], |
||
192 | 'education_grade_id' => $admissionInfo['education_grade']->id, |
||
193 | 'academic_period_id' => $admissionInfo['academic_period']->id, |
||
194 | ])->update( |
||
195 | [ |
||
196 | 'taking_g5_exam' => $student['taking_g5_exam'], |
||
197 | 'taking_ol_exam' => $student['taking_ol_exam'], |
||
198 | 'taking_al_exam' => $student['taking_al_exam'], |
||
199 | // Set special examination center |
||
200 | 'exam_center_for_special_education_g5' => $student['taking_g5_exam'] ? $student['sp_center'] : 0, |
||
201 | 'exam_center_for_special_education_ol' => $student['taking_ol_exam'] ? $student['sp_center'] : 0, |
||
202 | 'exam_center_for_special_education_al' => $student['taking_al_exam'] ? $student['sp_center'] : 0, |
||
203 | 'updated_from' => 'doe', |
||
204 | 'income_at_g5' => $student['a_income'], |
||
205 | 'modified' => now(), |
||
206 | 'modified_user_id' => 1 |
||
207 | ] |
||
208 | ); |
||
209 | } catch (\Throwable $th) { |
||
210 | Log::error($th); |
||
211 | } |
||
212 | } |
||
213 | |||
214 | public static function updateStudentArea(array $student){ |
||
254 | } |
||
255 | } |
||
256 | |||
257 | public static function createOrUpdate($studentId,$row,$params,$file){ |
||
273 |