Conditions | 6 |
Paths | 5 |
Total Lines | 58 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 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 |
||
58 | public function store(NewTipRequest $request) |
||
59 | { |
||
60 | // Determine if we are in the process of uploading a file, or if this is the initial request |
||
61 | if($request->file) |
||
62 | { |
||
63 | $status = $this->getChunk($request, $this->disk, $this->tmpFolder); |
||
64 | |||
65 | // If the file is completely uploaded, save the name and location in session data and move onto the next file |
||
66 | if($status['done'] === 100) |
||
67 | { |
||
68 | $newFile = FileUploads::create([ |
||
69 | 'disk' => $this->disk, |
||
70 | 'folder' => $this->tmpFolder, |
||
71 | 'file_name' => $status['filename'], |
||
72 | 'public' => 1, |
||
73 | ]); |
||
74 | |||
75 | $fileArr = session('new-file-upload') !== null ? session('new-file-upload') : []; |
||
76 | $fileArr[] = $newFile; |
||
77 | |||
78 | session(['new-file-upload' => $fileArr]); |
||
79 | |||
80 | return response()->noContent(); |
||
81 | } |
||
82 | |||
83 | // Continue the file upload |
||
84 | return response($status); |
||
85 | } |
||
86 | |||
87 | // All file uploads are done, create the new Tech Tip |
||
88 | $newTip = TechTip::create([ |
||
89 | 'user_id' => $request->user()->user_id, |
||
90 | 'tip_type_id' => $request->tip_type_id, |
||
91 | 'sticky' => $request->sticky, |
||
92 | 'subject' => $request->subject, |
||
93 | 'slug' => Str::slug($request->subject), |
||
94 | 'details' => $request->details, |
||
95 | ]); |
||
96 | |||
97 | |||
98 | // Move the files into a folder with the name of the tip_id |
||
99 | if(session('new-file-upload') !== null) |
||
100 | { |
||
101 | $files = session('new-file-upload'); |
||
102 | foreach($files as $file) |
||
103 | { |
||
104 | $this->moveFile($file->file_id, $this->disk, $newTip->tip_id); |
||
105 | TechTipFile::create([ |
||
106 | 'tip_id' => $newTip->tip_id, |
||
107 | 'file_id' => $file->file_id, |
||
108 | ]); |
||
109 | } |
||
110 | |||
111 | session()->forget('new-file-upload'); |
||
112 | } |
||
113 | |||
114 | Log::channel('user')->info('New Tech Tip - '.$request->subject.' was created by '.$request->user()->username); |
||
115 | return redirect(route('tech-tips.show', $newTip->slug)); |
||
116 | } |
||
164 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.