Test Setup Failed
Pull Request — master (#661)
by Mohamed
13:18
created
app/Imports/UsersImport.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
     public function registerEvents(): array
76 76
     {
77 77
         return [
78
-            BeforeSheet::class => function (BeforeSheet $event) {
78
+            BeforeSheet::class => function(BeforeSheet $event) {
79 79
                 $this->sheetNames[] = $event->getSheet()->getTitle();
80 80
                 $this->worksheet = $event->getSheet();
81 81
                 $this->validateClass();
@@ -87,7 +87,7 @@  discard block
 block discarded – undo
87 87
                     throw new \Maatwebsite\Excel\Validators\ValidationException($error, $failures);
88 88
                 }
89 89
             },
90
-            BeforeImport::class => function (BeforeImport $event) {
90
+            BeforeImport::class => function(BeforeImport $event) {
91 91
                 $this->highestRow = ($event->getReader()->getDelegate()->getActiveSheet()->getHighestDataRow('C'));
92 92
                 if ($this->highestRow < 3) {
93 93
                     $error = \Illuminate\Validation\ValidationException::withMessages([]);
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
                 $row = $this->setGender($row);
116 116
                 $mandatorySubject = Institution_class_subject::getMandatorySubjects($this->file['institution_class_id']);
117 117
                 $subjects = getMatchingKeys($row);
118
-                $student = Security_user::createOrUpdateStudentProfile($row,'create',$this->file);  
118
+                $student = Security_user::createOrUpdateStudentProfile($row, 'create', $this->file);  
119 119
                 $academicPeriod = Academic_period::where('id', '=', $institutionClass->academic_period_id)->first();
120 120
                 $institutionGrade = Institution_class_grade::where('institution_class_id', '=', $institutionClass->id)->first();
121 121
                 $assignee_id = $institutionClass->staff_id ? $institutionClass->staff_id : $this->file['security_user_id'];
@@ -128,24 +128,24 @@  discard block
 block discarded – undo
128 128
                     'institution_class' => $institutionClass
129 129
                 ];
130 130
 
131
-                Institution_student_admission::createAdmission($student->id,$row,$params,$this->file);
132
-                Institution_student::createOrUpdate($student->id,$row,$params,$this->file);
133
-                $student = Institution_class_student::createOrUpdate($student->id,$params,$this->file);
134
-                User_special_need::createOrUpdate($student->student_id,$row,$this->file);
135
-                User_body_mass::createOrUpdate($student->student_id,$row,$this->file);
131
+                Institution_student_admission::createAdmission($student->id, $row, $params, $this->file);
132
+                Institution_student::createOrUpdate($student->id, $row, $params, $this->file);
133
+                $student = Institution_class_student::createOrUpdate($student->id, $params, $this->file);
134
+                User_special_need::createOrUpdate($student->student_id, $row, $this->file);
135
+                User_body_mass::createOrUpdate($student->student_id, $row, $this->file);
136 136
 
137
-                $this->createOrUpdateGuardian($row,$student,'father');
138
-                $this->createOrUpdateGuardian($row,$student,'mother');
139
-                $this->createOrUpdateGuardian($row,$student,'guardian');
137
+                $this->createOrUpdateGuardian($row, $student, 'father');
138
+                $this->createOrUpdateGuardian($row, $student, 'mother');
139
+                $this->createOrUpdateGuardian($row, $student, 'guardian');
140 140
         
141 141
                 Institution_student::updateStudentArea($student->toArray());
142 142
 
143
-                $this->insertOrUpdateSubjects($row,$student,$institution);
143
+                $this->insertOrUpdateSubjects($row, $student, $institution);
144 144
 
145 145
                 $totalStudents = Institution_class_student::getStudentsCount($this->file['institution_class_id']);
146 146
                 if ($totalStudents['total'] > $institutionClass->no_of_students) {
147 147
                     $error = \Illuminate\Validation\ValidationException::withMessages([]);
148
-                    $failure = new Failure(3, 'rows', [3 => 'Class student count exceeded! Max number of students is ' . $institutionClass->no_of_students], [null]);
148
+                    $failure = new Failure(3, 'rows', [3 => 'Class student count exceeded! Max number of students is '.$institutionClass->no_of_students], [null]);
149 149
                     $failures = [0 => $failure];
150 150
                     throw new \Maatwebsite\Excel\Validators\ValidationException($error, $failures);
151 151
                     Log::info('email-sent', [$this->file]);
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
                 $institutionClass = new Institution_class();
155 155
                 $institutionClass->updateClassCount($this->file);
156 156
             }
157
-        } catch (\Maatwebsite\Excel\Validators\ValidationException $e) {
157
+        }catch (\Maatwebsite\Excel\Validators\ValidationException $e) {
158 158
             $error = \Illuminate\Validation\ValidationException::withMessages([]);
159 159
             $failures = $e->failures();
160 160
             throw new \Maatwebsite\Excel\Validators\ValidationException($error, $failures);
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
             '*.full_name' => 'required|regex:/^[a-zA-Z .]*$/u|max:256',
170 170
             '*.preferred_name' => 'nullable|regex:/^[a-zA-Z .]*$/u|max:90',
171 171
             '*.gender_mf' => 'required|in:M,F',
172
-            '*.date_of_birth_yyyy_mm_dd' => 'date|required|admission_age:' . $this->file['institution_class_id'],
172
+            '*.date_of_birth_yyyy_mm_dd' => 'date|required|admission_age:'.$this->file['institution_class_id'],
173 173
             '*.address' => 'nullable',
174 174
             '*.birth_registrar_office_as_in_birth_certificate' => 'nullable|exists:area_administratives,name|required_if:identity_type,BC|birth_place',
175 175
             '*.birth_divisional_secretariat' => 'nullable|exists:area_administratives,name|required_with:birth_registrar_office_as_in_birth_certificate',
@@ -178,8 +178,8 @@  discard block
 block discarded – undo
178 178
             '*.identity_number' => 'nullable|identity:identity_type|required_with:*.identity_type',
179 179
             '*.education_grade' => 'required',
180 180
             '*.option_*' => 'nullable|exists:education_subjects,name',
181
-            '*.bmi_height' => 'bail|required_with:*.bmi_weight|bmi:' . $this->file['institution_class_id'],
182
-            '*.bmi_weight' => 'bail|required_with:*.bmi_height|bmi:' . $this->file['institution_class_id'],
181
+            '*.bmi_height' => 'bail|required_with:*.bmi_weight|bmi:'.$this->file['institution_class_id'],
182
+            '*.bmi_weight' => 'bail|required_with:*.bmi_height|bmi:'.$this->file['institution_class_id'],
183 183
             '*.bmi_date_yyyy_mm_dd' => 'bail|required_with:*.bmi_height|date', //bmi:'. $this->file['institution_class_id'].'
184 184
             '*.bmi_academic_period' => 'bail|required_with:*.bmi_height|exists:academic_periods,name',
185 185
             '*.admission_no' => 'required|max:12|min:4|regex:/^[A-Za-z0-9\/]+$/',
Please login to merge, or discard this patch.
app/Providers/ValidatorExtended.php 1 patch
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -71,17 +71,17 @@  discard block
 block discarded – undo
71 71
             if (empty($value)) {
72 72
                 return false;
73 73
             } elseif ($gradeEntity !== null) {
74
-                $admissionAge = (($gradeEntity->admission_age) * 12) - 1;
74
+                $admissionAge = (($gradeEntity->admission_age)*12) - 1;
75 75
                 $to = $academicPeriod->start_date;
76 76
                 $diff_in_months = $to->diffInMonths($value);
77 77
                 $ageOfStudent = $diff_in_months;
78 78
                 $enrolmentMaximumAge = $admissionAge + 120;
79 79
                 return ($ageOfStudent <= $enrolmentMaximumAge) && ($ageOfStudent >= $admissionAge);
80
-            } else {
80
+            }else {
81 81
                 return false;
82 82
             }
83
-        } else {
84
-            $this->_custom_messages['admission_age'] = 'given' . $attribute . 'Not found';
83
+        }else {
84
+            $this->_custom_messages['admission_age'] = 'given'.$attribute.'Not found';
85 85
             $this->_set_custom_stuff();
86 86
             return false;
87 87
         }
@@ -92,16 +92,16 @@  discard block
 block discarded – undo
92 92
 
93 93
         if (is_numeric($value)) {
94 94
             if ($value < 10) {
95
-                $this->_custom_messages['bmi'] =  $attribute . ' is must greater than 10';
95
+                $this->_custom_messages['bmi'] = $attribute.' is must greater than 10';
96 96
                 $this->_set_custom_stuff();
97 97
                 return false;
98 98
             } elseif ($value > 250) {
99
-                $this->_custom_messages['bmi'] =  $attribute . ' is must smaller than 250';
99
+                $this->_custom_messages['bmi'] = $attribute.' is must smaller than 250';
100 100
                 $this->_set_custom_stuff();
101 101
                 return false;
102 102
             }
103
-        } else {
104
-            $this->_custom_messages['bmi'] =  $attribute . ' is must a valid numeric';
103
+        }else {
104
+            $this->_custom_messages['bmi'] = $attribute.' is must a valid numeric';
105 105
             $this->_set_custom_stuff();
106 106
             return false;
107 107
         }
@@ -110,18 +110,18 @@  discard block
 block discarded – undo
110 110
 
111 111
     protected function validateBmi($attribute, $value, $parameters)
112 112
     {
113
-        $bmiGrades =  ['G1', 'G4', 'G7', 'G10'];
113
+        $bmiGrades = ['G1', 'G4', 'G7', 'G10'];
114 114
         $institutionGrade = Institution_class_grade::where('institution_class_id', '=', $parameters[0])
115 115
             ->join('education_grades', 'institution_class_grades.education_grade_id', 'education_grades.id')
116 116
             ->first();
117
-        $educationGrade =  Education_grade::where('id', '=', $institutionGrade->education_grade_id)->first();
117
+        $educationGrade = Education_grade::where('id', '=', $institutionGrade->education_grade_id)->first();
118 118
         if (in_array($institutionGrade->code, $bmiGrades)) {
119 119
             if (!empty($value)) {
120 120
                 if (($attribute == 'bmi_height') || ('bmi_weight')) {
121 121
                     return $this->validateHW($attribute, $value);
122 122
                 }
123
-            } else {
124
-                $this->_custom_messages['bmi'] =  $attribute . ' is required for ' . $educationGrade->name;
123
+            }else {
124
+                $this->_custom_messages['bmi'] = $attribute.' is required for '.$educationGrade->name;
125 125
                 $this->_set_custom_stuff();
126 126
                 return false;
127 127
             }
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
             if (($attribute == 'bmi_height') || ('bmi_weight')) {
130 130
                 return $this->validateHW($attribute, $value);
131 131
             }
132
-        } else {
132
+        }else {
133 133
             return true;
134 134
         }
135 135
     }
@@ -138,19 +138,19 @@  discard block
 block discarded – undo
138 138
     {
139 139
         foreach ($validator->getData() as $data) {
140 140
             if ($data['identity_type'] == 'BC' && key_exists('birth_divisional_secretariat', $data)) {
141
-                $BirthDivision = Area_administrative::where('name', '=',  '%' . $data['birth_divisional_secretariat'] . '%')->where('area_administrative_level_id', '=', 5); //
141
+                $BirthDivision = Area_administrative::where('name', '=', '%'.$data['birth_divisional_secretariat'].'%')->where('area_administrative_level_id', '=', 5); //
142 142
                 if ($BirthDivision->count() > 0) {
143
-                    $BirthArea = Area_administrative::where('name', '=', '%' . $value . '%') //$data['birth_registrar_office_as_in_birth_certificate']
143
+                    $BirthArea = Area_administrative::where('name', '=', '%'.$value.'%') //$data['birth_registrar_office_as_in_birth_certificate']
144 144
                         ->where('parent_id', '=', $BirthDivision->first()->id)->count();
145
-                    return $BirthArea  > 0;
145
+                    return $BirthArea > 0;
146 146
                 } elseif (key_exists('birth_divisional_secretariat', $data) && (!key_exists('birth_registrar_office_as_in_birth_certificate', $data))) {
147 147
                     $this->_custom_messages['birth_place'] = 'birth_registrar_office_as_in_birth_certificate required with BC';
148 148
                     $this->_set_custom_stuff();
149 149
                     return false;
150
-                } else {
150
+                }else {
151 151
                     return true;
152 152
                 }
153
-            } else {
153
+            }else {
154 154
                 return true;
155 155
             }
156 156
         }
@@ -158,16 +158,16 @@  discard block
 block discarded – undo
158 158
 
159 159
     protected function validateIsStudentInClass($attribute, $value, $perameters, $validator)
160 160
     {
161
-        $student =  Security_user::where('openemis_no', '=', $value);
161
+        $student = Security_user::where('openemis_no', '=', $value);
162 162
         if ($student->count() > 0) {
163 163
             $student = $student->first()->toArray();
164
-            $check =  Institution_class_student::where('student_id', '=', $student['id'])->where('institution_class_id', '=', $perameters[0])->count();
164
+            $check = Institution_class_student::where('student_id', '=', $student['id'])->where('institution_class_id', '=', $perameters[0])->count();
165 165
             if ($check == 1) {
166 166
                 return true;
167
-            } else {
167
+            }else {
168 168
                 return false;
169 169
             }
170
-        } else {
170
+        }else {
171 171
             return false;
172 172
         }
173 173
     }
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
     {
179 179
         $valid = true;
180 180
         foreach ($validator->getData() as $data) {
181
-            switch($data[$perameters[0]]){
181
+            switch ($data[$perameters[0]]) {
182 182
                 case 'BC':
183 183
                     $valid = preg_match('/^([0-9]{3,5})$/i', $value);
184 184
                     break;
@@ -191,10 +191,10 @@  discard block
 block discarded – undo
191 191
         }
192 192
         
193 193
         if (!$valid) {
194
-            $this->_custom_messages['nic'] = $attribute . ' is not valid,  Please check the NIC number';
194
+            $this->_custom_messages['nic'] = $attribute.' is not valid,  Please check the NIC number';
195 195
             $this->_set_custom_stuff();
196 196
             return false;
197
-        } else {
197
+        }else {
198 198
             return true;
199 199
         }
200 200
     }
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
     protected function validateUserUnique($attribute, $value, $perameters, $validator)
203 203
     {
204 204
         foreach ($validator->getData() as $data) {
205
-            $identityType = Identity_type::where('national_code', 'like', '%' . $data['identity_type'] . '%')->first();
205
+            $identityType = Identity_type::where('national_code', 'like', '%'.$data['identity_type'].'%')->first();
206 206
             if ($identityType !== null && ($value !== null)) {
207 207
                 if ($identityType->national_code === 'BC') {
208 208
                     return $this->checkUnique($value, $data, $identityType);
@@ -218,14 +218,14 @@  discard block
 block discarded – undo
218 218
     protected function validateIsBc($attribute, $value, $perameters, $validator)
219 219
     {
220 220
         foreach ($validator->getData() as $data) {
221
-            $identityType = Identity_type::where('national_code', 'like', '%' . $data['identity_type'] . '%')->first();
221
+            $identityType = Identity_type::where('national_code', 'like', '%'.$data['identity_type'].'%')->first();
222 222
             if (($identityType !== null) && ($identityType !== "")) {
223 223
                 if (($identityType->national_code) === 'BC') {
224 224
                     return (strlen((string) $data['identity_number']) < 7);
225
-                } else {
225
+                }else {
226 226
                     return true;
227 227
                 }
228
-            } else {
228
+            }else {
229 229
                 return true;
230 230
             }
231 231
         }
@@ -235,24 +235,24 @@  discard block
 block discarded – undo
235 235
     {
236 236
         $isUnique = Security_user::where('identity_number', '=', $value)->where('identity_type_id', '=', $identityType->id);
237 237
         if ($isUnique->count() > 0) {
238
-            $this->_custom_messages['user_unique'] = 'The identity number already in use. User ID is : ' . $isUnique->first()->openemis_no;
238
+            $this->_custom_messages['user_unique'] = 'The identity number already in use. User ID is : '.$isUnique->first()->openemis_no;
239 239
             $this->_set_custom_stuff();
240 240
             return false;
241
-        } else {
241
+        }else {
242 242
             return true;
243 243
         }
244 244
     }
245 245
 
246 246
     protected function IsBc($data, $value)
247 247
     {
248
-        $identityType = Identity_type::where('national_code', 'like', '%' . $data['identity_type'] . '%')->first();
248
+        $identityType = Identity_type::where('national_code', 'like', '%'.$data['identity_type'].'%')->first();
249 249
         if ($identityType !== null) {
250 250
             if (($identityType->national_code) === 'BC' && strlen((string) $value) < 8) {
251 251
                 return false;
252
-            } else {
252
+            }else {
253 253
                 return true;
254 254
             }
255
-        } else {
255
+        }else {
256 256
             return true;
257 257
         }
258 258
     }
Please login to merge, or discard this patch.