Conditions | 5 |
Paths | 1 |
Total Lines | 82 |
Code Lines | 64 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
81 | protected function form() |
||
82 | { |
||
83 | $form=new Form(new Abuse); |
||
84 | |||
85 | $form->text('title', __('Title')); |
||
86 | $form->number('cause', __('Cause')); |
||
87 | $form->textarea('supplement', __('Supplement')); |
||
88 | $form->textarea('link', __('Link')); |
||
89 | $form->switch('audit', __('Audit')); |
||
90 | $form->number('user_id', __('User id')); |
||
91 | |||
92 | $form->ignore(['created_at']); |
||
93 | |||
94 | $form->saving(function(Form $form) { |
||
95 | $abuse=$form->model(); |
||
96 | //get gategory and subject id |
||
97 | $regex='/^([A-Za-z]+) #(\d+)/'; |
||
98 | $matches=[]; |
||
99 | preg_match($regex, $abuse->title, $matches); |
||
100 | $category=array_search(strtolower($matches[1]), Abuse::$supportCategory); |
||
101 | $subject_id=(int) $matches[2]; |
||
102 | switch ($abuse->category) { |
||
103 | case 0: |
||
104 | $gid=$subject_id; |
||
105 | $group=Group::find($gid); |
||
106 | if (empty($group)) { |
||
107 | return; |
||
108 | } |
||
109 | if ($form->audit) { |
||
110 | $ban_time=request()->created_at; |
||
111 | sendMessage([ |
||
112 | 'sender' => config('app.official_sender'), |
||
113 | 'receiver' => $abuse->user_id, |
||
114 | 'level' => 5, |
||
115 | 'title' => "Your abuse report about group {$group->name} was passed", |
||
116 | 'content' => "Hi, Dear **{$abuse->user->name}**,\n\nWe have checked your Abuse report about group **[{$group->name}]({$group->link})**.\n\n We think you're right.\n\n So as the consequence leading to a temporary/permanent sanction against the group.\n\n Thank you for your contribution to our community environment.\n\n Sincerely, NOJ" |
||
117 | ]); |
||
118 | sendMessage([ |
||
119 | 'sender' => config('app.official_sender'), |
||
120 | 'receiver' => $group->leader->id, |
||
121 | 'level' => 3, |
||
122 | 'title' => "Your group {$group->name} has been banned.", |
||
123 | 'content' => "Hi, Dear **{$group->leader->name}**,\n\n For the following reasons: \n\n {$abuse->supplement}\n\n your group **[{$group->name}]({$group->link})** is currently banned and will continue until {$ban_time}.\n\n Before this, only you can enter the group. \n\n Please rectify before this, or you may be subjected to more serious treatment.\n\n Thank you for your contribution to our community environment.\n\n Sincerely, NOJ" |
||
124 | ]); |
||
125 | $abuse->delete(); |
||
126 | GroupBanned::create([ |
||
127 | 'abuse_id' => $abuse->id, |
||
128 | 'group_id' => $group->gid, |
||
129 | 'reason' => $abuse->supplement, |
||
130 | 'removed_at' => $ban_time |
||
131 | ]); |
||
132 | return; |
||
133 | } else { |
||
134 | sendMessage([ |
||
135 | 'sender' => config('app.official_sender'), |
||
136 | 'receiver' => $abuse->user_id, |
||
137 | 'level' => 2, |
||
138 | 'title' => "Your abuse report about group {$group->name} was rejected", |
||
139 | 'content' => "Hi, Dear **{$abuse->user->name}**,\n\n We have checked your Abuse report about group **[{$group->name}]({$group->link})**.\n\n However, we regret to say that the information you submitted is not sufficient for us to take action.\n\n Of course, we will continue to follow up the investigation.\n\n Thank you for your contribution to our community environment.\n\n Sincerely, NOJ" |
||
140 | ]); |
||
141 | $abuse->delete(); |
||
142 | return; |
||
143 | } |
||
144 | return; |
||
145 | case 1: |
||
146 | $ban_time=request()->created_at; |
||
147 | UserBanned::create([ |
||
148 | 'abuse_id' => $abuse->id, |
||
149 | 'user_id' => $subject_id, |
||
150 | 'reason' => $abuse->supplement, |
||
151 | 'removed_at' => $ban_time |
||
152 | ]); |
||
153 | $abuse->delete(); |
||
154 | return; |
||
155 | default: |
||
156 | return; |
||
157 | } |
||
158 | |||
159 | |||
160 | }); |
||
161 | |||
162 | return $form; |
||
163 | } |
||
188 |