Conditions | 1 |
Paths | 1 |
Total Lines | 56 |
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 |
||
202 | protected function renderDelete() |
||
203 | { |
||
204 | $deleteConfirm = trans('admin.delete_confirm'); |
||
205 | $confirm = trans('admin.confirm'); |
||
206 | $cancel = trans('admin.cancel'); |
||
207 | |||
208 | $class = uniqid(); |
||
209 | |||
210 | $script = <<<SCRIPT |
||
211 | |||
212 | $('.{$class}-delete').unbind('click').click(function() { |
||
213 | |||
214 | swal({ |
||
215 | title: "$deleteConfirm", |
||
216 | type: "warning", |
||
217 | showCancelButton: true, |
||
218 | confirmButtonColor: "#DD6B55", |
||
219 | confirmButtonText: "$confirm", |
||
220 | closeOnConfirm: false, |
||
221 | cancelButtonText: "$cancel" |
||
222 | }, |
||
223 | function(){ |
||
224 | $.ajax({ |
||
225 | method: 'post', |
||
226 | url: '{$this->getDeletePath()}', |
||
227 | data: { |
||
228 | _method:'delete', |
||
229 | _token:LA.token, |
||
230 | }, |
||
231 | success: function (data) { |
||
232 | $.pjax.reload('#pjax-container'); |
||
233 | |||
234 | if (typeof data === 'object') { |
||
235 | if (data.status) { |
||
236 | swal(data.message, '', 'success'); |
||
237 | } else { |
||
238 | swal(data.message, '', 'error'); |
||
239 | } |
||
240 | } |
||
241 | } |
||
242 | }); |
||
243 | }); |
||
244 | }); |
||
245 | |||
246 | SCRIPT; |
||
247 | |||
248 | Admin::script($script); |
||
249 | |||
250 | return <<<HTML |
||
251 | <div class="btn-group pull-right" style="margin-right: 5px"> |
||
252 | <a href="javascript:void(0);" class="btn btn-sm btn-danger {$class}-delete"> |
||
253 | <i class="fa fa-trash"></i> |
||
254 | </a> |
||
255 | </div> |
||
256 | HTML; |
||
257 | } |
||
258 | |||
276 |