Conditions | 2 |
Paths | 2 |
Total Lines | 59 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
36 | public function upload(Request $request){ |
||
37 | |||
38 | |||
39 | |||
40 | $validator = Validator::make( |
||
41 | [ |
||
42 | 'import_file' => $request->import_file, |
||
43 | 'extension' => strtolower($request->import_file->getClientOriginalExtension()), |
||
44 | 'class' => $request->class, |
||
45 | 'email' => auth()->user()->email |
||
46 | ], |
||
47 | [ |
||
48 | 'import_file' => 'required', |
||
49 | 'extension' => 'required|in:xlsx,xls,ods|max:2048', |
||
50 | 'class' => 'required', |
||
51 | 'email' => 'required' |
||
52 | |||
53 | ], |
||
54 | ['email.required' => 'You dont have email in your account, pleas contact your Zonal/Provincial Coordinator and update the email to get notification'] |
||
55 | ); |
||
56 | // try { |
||
57 | // $result = $this->ses->verifyEmailIdentity([ |
||
58 | // 'EmailAddress' => auth()->user()->email, |
||
59 | // ]); |
||
60 | // var_dump($result); |
||
61 | // } catch (AwsException $e) { |
||
62 | // // output error message if fails |
||
63 | // echo $e->getMessage(); |
||
64 | // echo "\n"; |
||
65 | // } |
||
66 | // if ($validator->fails()) { |
||
67 | // return back() |
||
68 | // ->withErrors($validator); |
||
69 | // } |
||
70 | |||
71 | |||
72 | $uploadFile = $validator->validated()['import_file']; |
||
73 | $class = Institution_class::find($validator->validated()['class']); |
||
74 | // dd(auth()->user()->principal[0]->institution_group[0]->institution); |
||
75 | $institution = auth()->user()->permissions->isEmpty() ? auth()->user()->principal[0]->institution_group[0]->institution->code : auth()->user()->permissions[0]->institution_staff->institution->code; |
||
76 | |||
77 | |||
78 | $fileName = time().'_'.$institution.'_'.str_replace(' ','_', clean($class->name)).'_'.auth()->user()->openemis_no.'_student_bulk_data.xlsx'; |
||
79 | Storage::disk('local')->putFileAs( |
||
80 | 'sis-bulk-data-files/', |
||
81 | $uploadFile, |
||
82 | $fileName |
||
83 | ); |
||
84 | |||
85 | $upload = new Upload; |
||
86 | $upload->fileName =$fileName; |
||
87 | $upload->model = 'Student'; |
||
88 | $upload->node = 'None'; |
||
89 | $upload->institution_class_id = $class->id; |
||
90 | $upload->user()->associate(auth()->user()); |
||
91 | $upload->save(); |
||
92 | |||
93 | |||
94 | return redirect('/')->withSuccess('The file is uploaded, we will process and let you know by your email'); |
||
95 | } |
||
162 |