| Total Complexity | 40 |
| Total Lines | 257 |
| Duplicated Lines | 0 % |
| Changes | 5 | ||
| 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) |
||
| 118 | { |
||
| 119 | return $this |
||
| 120 | ->select( |
||
| 121 | 'institution_students.id', |
||
| 122 | 'institution_students.student_id', |
||
| 123 | 'institution_students.student_status_id', |
||
| 124 | 'institution_students.education_grade_id', |
||
| 125 | 'institution_students.education_grade_id', |
||
| 126 | 'institution_students.academic_period_id', |
||
| 127 | 'institution_students.institution_id', |
||
| 128 | 'institution_students.created_user_id', |
||
| 129 | 'institution_students.admission_id' |
||
| 130 | ) |
||
| 131 | ->where('institution_students.institution_id', $institutionGrade['institution_id']) |
||
| 132 | ->where('institution_students.student_status_id',1) |
||
| 133 | ->where('institution_students.education_grade_id', $institutionGrade['education_grade_id']) |
||
| 134 | ->where('institution_students.deleted_at',null) |
||
| 135 | ->where('institution_students.academic_period_id', $academicPeriod->id)->get()->toArray(); |
||
| 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) |
||
| 174 | } |
||
| 175 | } |
||
| 176 | |||
| 177 | /** |
||
| 178 | * Update new Institution student from examination data |
||
| 179 | * |
||
| 180 | * @param [type] $student |
||
| 181 | * @param [type] $admissionInfo |
||
| 182 | * @return void |
||
| 183 | */ |
||
| 184 | public static function updateExaminationData($student, $admissionInfo) |
||
| 209 | } |
||
| 210 | } |
||
| 211 | |||
| 212 | public static function updateStudentArea(array $student){ |
||
| 253 | } |
||
| 254 | } |
||
| 255 | |||
| 256 | public static function createOrUpdate($studentId,$row,$params,$file){ |
||
| 272 |