| Conditions | 7 | 
| Paths | 1 | 
| Total Lines | 53 | 
| Code Lines | 40 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 2 | ||
| Bugs | 1 | 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  | 
            ||
| 125 | protected function form()  | 
            ||
| 126 |     { | 
            ||
| 127 | $form=new Form(new Group);  | 
            ||
| 128 |         $form->model()->makeVisible('password'); | 
            ||
| 129 |         $form->tab('Basic', function(Form $form) { | 
            ||
| 130 |             $form->text('gcode')->rules('required|alpha_dash|min:3|max:50'); | 
            ||
| 131 |             $form->text('name')->rules('required|min:3|max:50'); | 
            ||
| 132 |             $form->switch('public')->default(true); | 
            ||
| 133 |             $form->textarea('description')->rules('nullable|max:60000'); | 
            ||
| 134 |             $form->select('join_policy', 'Join Policy')->options([ | 
            ||
| 135 | 0 => "Cannot Join",  | 
            ||
| 136 | 1 => "Invite Only",  | 
            ||
| 137 | 2 => "Apply Only",  | 
            ||
| 138 | 3 => "Invite & Apply"  | 
            ||
| 139 | ])->default(1);  | 
            ||
| 140 |             $form->image('img', 'Custom Group Focus Image')->uniqueName()->move("static/img/group"); | 
            ||
| 141 |             if ($form->isCreating()) { | 
            ||
| 142 |                 $form->select('leader_uid', 'Group Leader')->options(function ($id) { | 
            ||
| 143 | $user = User::find($id);  | 
            ||
| 144 |                     if ($user) { | 
            ||
| 145 | return [$user->id => $user->readable_name];  | 
            ||
| 146 | }  | 
            ||
| 147 |                 })->config('minimumInputLength', 4)->ajax(route('admin.api.users'))->required(); | 
            ||
| 148 | }  | 
            ||
| 149 | $form->ignore(['leader_uid']);  | 
            ||
| 150 |             $form->saving(function(Form $form) { | 
            ||
| 151 |                 $err=function($msg, $title='Error occur.') { | 
            ||
| 152 | $error=new MessageBag([  | 
            ||
| 153 | 'title' => $title,  | 
            ||
| 154 | 'message' => $msg,  | 
            ||
| 155 | ]);  | 
            ||
| 156 |                     return back()->with(compact('error')); | 
            ||
| 157 | };  | 
            ||
| 158 | $gcode=$form->gcode;  | 
            ||
| 159 |                 $g=Group::where('gcode', $gcode)->first(); | 
            ||
| 160 | //check gcode has been token.  | 
            ||
| 161 | $gid=$form->model()->gid ?? null;  | 
            ||
| 162 |                 if (!empty($gcode) && !blank($g) && $g->gid!=$gid) { | 
            ||
| 163 |                     return $err('Gcode has been token', 'Error occur.'); | 
            ||
| 164 | }  | 
            ||
| 165 | });  | 
            ||
| 166 |             $form->saved(function(Form $form) { | 
            ||
| 167 |                 if ($form->isCreating()) { | 
            ||
| 168 | $form->model()->members()->saveMany([new GroupMember([  | 
            ||
| 169 | 'gid' => $form->model()->gid,  | 
            ||
| 170 |                         'uid' => request('leader_uid'), | 
            ||
| 171 | 'role' => 3,  | 
            ||
| 172 | 'ranking' => 1500,  | 
            ||
| 173 | ])]);  | 
            ||
| 174 | }  | 
            ||
| 175 | });  | 
            ||
| 176 | });  | 
            ||
| 177 | return $form;  | 
            ||
| 178 | }  | 
            ||
| 180 |