| Conditions | 28 |
| Paths | 1 |
| Total Lines | 98 |
| Code Lines | 70 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 14 | public function index() |
||
| 15 | { |
||
| 16 | return Datatables::of(Upload::with(['classRoom'])->where('security_user_id','=',Auth::user()->id)) |
||
|
|
|||
| 17 | ->editColumn('is_processed', function ($data) { |
||
| 18 | |||
| 19 | $nowTime = \Carbon\Carbon::now(); |
||
| 20 | $to = \Carbon\Carbon::createFromFormat('Y-m-d H:s:i', $nowTime); |
||
| 21 | $from = \Carbon\Carbon::createFromFormat('Y-m-d H:s:i', $data->updated_at); |
||
| 22 | $diff_in_hours = $to->diffInHours($from); |
||
| 23 | |||
| 24 | if($diff_in_hours >= 2 && $data->is_processed == 3){ |
||
| 25 | return "Terminated"; |
||
| 26 | } |
||
| 27 | elseif ($data->is_processed === 1) { |
||
| 28 | return "Success"; |
||
| 29 | }elseif ($data->is_processed === 2){ |
||
| 30 | return "Failed"; |
||
| 31 | }elseif($diff_in_hours < 2 && $data->is_processed == 3){ |
||
| 32 | return "Processing"; |
||
| 33 | }elseif ($data->is_processed == 4){ |
||
| 34 | return "Process Paused"; |
||
| 35 | }else{ |
||
| 36 | return 'Pending'; |
||
| 37 | }; |
||
| 38 | |||
| 39 | }) |
||
| 40 | ->editColumn('is_email_sent', function ($data) { |
||
| 41 | if ($data->is_email_sent == 1) { |
||
| 42 | return "Success"; |
||
| 43 | }elseif($data->is_email_sent == 2 ){ |
||
| 44 | return 'Failed'; |
||
| 45 | }else{ |
||
| 46 | return 'Pending'; |
||
| 47 | }; |
||
| 48 | |||
| 49 | }) |
||
| 50 | ->editColumn('update', function ($data) { |
||
| 51 | if ((int)$data->update == 0) { |
||
| 52 | return "No Processes"; |
||
| 53 | }elseif((int)$data->update == 1 ){ |
||
| 54 | return 'Success'; |
||
| 55 | }elseif((int)$data->update == 2 ){ |
||
| 56 | return 'Failed'; |
||
| 57 | }elseif((int)$data->update == 3 ){ |
||
| 58 | return 'Partial Success'; |
||
| 59 | }; |
||
| 60 | |||
| 61 | }) |
||
| 62 | ->editColumn('insert', function ($data) { |
||
| 63 | if ($data->insert == 0) { |
||
| 64 | return "No Processes"; |
||
| 65 | }elseif($data->insert == 1 ){ |
||
| 66 | return 'Success'; |
||
| 67 | }elseif($data->insert == 2 ){ |
||
| 68 | return 'Failed'; |
||
| 69 | }elseif($data->insert == 3 ){ |
||
| 70 | return 'Partial Success'; |
||
| 71 | }; |
||
| 72 | |||
| 73 | }) |
||
| 74 | ->editColumn('filename', function ($data) { |
||
| 75 | if(\App::environment('local') || \App::environment('stage')){ |
||
| 76 | return '<a href="/download_file/'.$data->filename.'">'.$data->classRoom->name.'</a>'; |
||
| 77 | |||
| 78 | }else{ |
||
| 79 | return '<a href="/bulk-upload/download_file/'.$data->filename.'">'.$data->classRoom->name.'</a>'; |
||
| 80 | } |
||
| 81 | |||
| 82 | }) |
||
| 83 | ->editColumn('error', function ($data) { |
||
| 84 | if(\App::environment('local') || \App::environment('stage')){ |
||
| 85 | return '<a href="/download/'.$data->filename.'">'.$data->classRoom->name.'</a>'; |
||
| 86 | |||
| 87 | }else{ |
||
| 88 | return '<a href="/bulk-upload/download/'.$data->filename.'">'.$data->classRoom->name.'</a>'; |
||
| 89 | } |
||
| 90 | |||
| 91 | })->editColumn('actions', function ($data) { |
||
| 92 | |||
| 93 | $nowTime = \Carbon\Carbon::now(); |
||
| 94 | $to = \Carbon\Carbon::createFromFormat('Y-m-d H:s:i', $nowTime); |
||
| 95 | $from = \Carbon\Carbon::createFromFormat('Y-m-d H:s:i', $data->updated_at); |
||
| 96 | $diff_in_hours = $to->diffInHours($from); |
||
| 97 | |||
| 98 | if($diff_in_hours >= 2 && $data->is_processed == 3){ |
||
| 99 | return '<button onclick="updateProcess('.($data->id).',100)" class="btn btn-primary text-uppercase">reprocess</button>'; |
||
| 100 | }elseif ($data->is_processed == 1){ |
||
| 101 | return '<div><h6>Processing <span class="badge badge-success text-uppercase">Successful</span></h6></div>'; |
||
| 102 | }elseif ($data->is_processed == 2){ |
||
| 103 | return '<div><h6>Processing <span class="badge badge-danger text-uppercase">Failed</span></h6></div>'; |
||
| 104 | }elseif ($data->is_processed == 0){ |
||
| 105 | return '<button onclick="updateProcess('.($data->id).',200)" class="btn btn-block btn-warning text-uppercase">pause</button>'; |
||
| 106 | }elseif ($data->is_processed == 4){ |
||
| 107 | return '<button onclick="updateProcess('.($data->id).',100)" class="btn btn-block btn-success text-uppercase">resume</button>'; |
||
| 108 | } |
||
| 109 | }) |
||
| 110 | ->rawColumns(['filename','error','actions']) |
||
| 111 | ->make(true); |
||
| 112 | } |
||
| 124 |