| Conditions | 8 |
| Paths | 9 |
| Total Lines | 57 |
| Code Lines | 41 |
| 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 |
||
| 24 | $all_data=$request->all(); |
||
| 25 | |||
| 26 | $groupModel=new GroupModel(); |
||
| 27 | $clearance=$groupModel->judgeClearance($all_data["gid"], Auth::user()->id); |
||
| 28 | if ($clearance<1) { |
||
| 29 | return ResponseModel::err(2001); |
||
| 30 | } |
||
| 31 | $groupModel->changeNickName($all_data["gid"], Auth::user()->id, $all_data["nick_name"]); |
||
| 32 | return ResponseModel::success(200); |
||
| 33 | } |
||
| 34 | |||
| 35 | public function joinGroup(Request $request) |
||
| 36 | { |
||
| 37 | $request->validate([ |
||
| 38 | 'gid' => 'required|integer', |
||
| 39 | ]); |
||
| 40 | |||
| 41 | $all_data=$request->all(); |
||
| 42 | |||
| 43 | $groupModel=new GroupModel(); |
||
| 44 | $join_policy=$groupModel->joinPolicy($all_data["gid"]); |
||
| 45 | if (is_null($join_policy)) { |
||
| 46 | return ResponseModel::err(7001); |
||
| 47 | } |
||
| 48 | $clearance=$groupModel->judgeClearance($all_data["gid"], Auth::user()->id); |
||
| 49 | if ($join_policy==3) { |
||
| 50 | if ($clearance==-1) { |
||
| 51 | $groupModel->changeClearance(Auth::user()->id, $all_data["gid"], 1); |
||
| 52 | } elseif ($clearance==-3) { |
||
| 53 | $groupModel->addClearance(Auth::user()->id, $all_data["gid"], 0); |
||
| 54 | } |
||
| 55 | return ResponseModel::success(200); |
||
| 56 | } |
||
| 57 | } |
||
| 58 | |||
| 59 | public function createGroup(Request $request) |
||
| 60 | { |
||
| 61 | $request->validate([ |
||
| 62 | 'gcode' => 'required|alpha_dash|min:3|max:50', |
||
| 63 | 'name' => 'required|min:3|max:50', |
||
| 64 | 'public' => 'required|integer|min:1|max:2', |
||
| 65 | 'description' => 'nullable|max:60000', |
||
| 66 | 'join_policy' => 'required|integer|min:1|max:3' |
||
| 67 | ]); |
||
| 68 | |||
| 69 | $all_data=$request->all(); |
||
| 70 | |||
| 71 | $groupModel=new GroupModel(); |
||
| 72 | if($all_data["gcode"]=="create") return ResponseModel::err(7005); |
||
| 73 | $is_group=$groupModel->isGroup($all_data["gcode"]); |
||
| 74 | if($is_group) return ResponseModel::err(7006); |
||
| 75 | |||
| 76 | $allow_extension=['jpg', 'png', 'jpeg', 'gif', 'bmp']; |
||
| 77 | if (!empty($request->file('img')) && $request->file('img')->isValid()) { |
||
| 78 | $extension=$request->file('img')->extension(); |
||
| 79 | if (!in_array($extension, $allow_extension)) { |
||
| 80 | return ResponseModel::err(1005); |
||
| 81 | } |
||
| 121 |