| Conditions | 25 |
| Paths | 25 |
| Total Lines | 155 |
| Code Lines | 110 |
| Lines | 105 |
| Ratio | 67.74 % |
| 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 |
||
| 76 | public function segments($segment) |
||
| 77 | { |
||
| 78 | if (strpos($segment, 'user') !== false) { |
||
| 79 | return $this->formatUserTickets($segment); |
||
| 80 | } |
||
| 81 | $table = $this->table(); |
||
| 82 | switch ($segment) { |
||
| 83 | View Code Duplication | case '/ticket/inbox': |
|
| 84 | if (Auth::user()->role == 'agent') { |
||
| 85 | $id = Auth::user()->primary_dpt; |
||
| 86 | $table = $table->where('tickets.dept_id', '=', $id)->orWhere('assigned_to', '=', Auth::user()->id); |
||
| 87 | } |
||
| 88 | |||
| 89 | return $table |
||
| 90 | ->Join('ticket_status', function ($join) { |
||
| 91 | $join->on('ticket_status.id', '=', 'tickets.status') |
||
| 92 | ->whereIn('ticket_status.id', [1, 7]); |
||
| 93 | }); |
||
| 94 | View Code Duplication | case '/ticket/closed': |
|
| 95 | if (Auth::user()->role == 'agent') { |
||
| 96 | $id = Auth::user()->primary_dpt; |
||
| 97 | $table = $table->where('tickets.dept_id', '=', $id); |
||
| 98 | } |
||
| 99 | |||
| 100 | return $table |
||
| 101 | ->Join('ticket_status', function ($join) { |
||
| 102 | $join->on('ticket_status.id', '=', 'tickets.status') |
||
| 103 | ->whereIn('ticket_status.state', ['closed']); |
||
| 104 | }); |
||
| 105 | case '/ticket/myticket': |
||
| 106 | return $table |
||
| 107 | ->leftJoin('ticket_status', function ($join) { |
||
| 108 | $join->on('ticket_status.id', '=', 'tickets.status'); |
||
| 109 | }) |
||
| 110 | ->orWhere('tickets.assigned_to', '=', Auth::user()->id) |
||
| 111 | ->where('tickets.status', '=', 1); |
||
| 112 | View Code Duplication | case '/unassigned': |
|
| 113 | if (Auth::user()->role == 'agent') { |
||
| 114 | $id = Auth::user()->primary_dpt; |
||
| 115 | $table = $table->where('tickets.dept_id', '=', $id); |
||
| 116 | } |
||
| 117 | |||
| 118 | return $table |
||
| 119 | ->leftJoin('ticket_status', function ($join) { |
||
| 120 | $join->on('ticket_status.id', '=', 'tickets.status'); |
||
| 121 | }) |
||
| 122 | ->where('tickets.assigned_to', '=', null) |
||
| 123 | ->where('tickets.status', '=', 1); |
||
| 124 | case '/ticket/overdue': |
||
| 125 | if (Auth::user()->role == 'agent') { |
||
| 126 | $id = Auth::user()->primary_dpt; |
||
| 127 | $table = $table->where('tickets.dept_id', '=', $id); |
||
| 128 | } |
||
| 129 | |||
| 130 | return $table |
||
| 131 | ->leftJoin('ticket_status', function ($join) { |
||
| 132 | $join->on('ticket_status.id', '=', 'tickets.status'); |
||
| 133 | }) |
||
| 134 | ->where('tickets.status', '=', 1) |
||
| 135 | ->where('tickets.isanswered', '=', 0) |
||
| 136 | ->whereNotNull('tickets.duedate') |
||
| 137 | ->where('tickets.duedate', '!=', '00-00-00 00:00:00') |
||
| 138 | |||
| 139 | // ->where('duedate','>',\Carbon\Carbon::now()); |
||
| 140 | ->where('tickets.duedate', '<', \Carbon\Carbon::now()); |
||
| 141 | View Code Duplication | case '/ticket/approval/closed': |
|
| 142 | if (Auth::user()->role == 'agent') { |
||
| 143 | $id = Auth::user()->primary_dpt; |
||
| 144 | $table = $table->where('tickets.dept_id', '=', $id); |
||
| 145 | } |
||
| 146 | |||
| 147 | return $table |
||
| 148 | ->Join('ticket_status', function ($join) { |
||
| 149 | $join->on('ticket_status.id', '=', 'tickets.status') |
||
| 150 | ->where('tickets.status', '=', 7); |
||
| 151 | }); |
||
| 152 | |||
| 153 | View Code Duplication | case '/trash': |
|
| 154 | if (Auth::user()->role == 'agent') { |
||
| 155 | $id = Auth::user()->primary_dpt; |
||
| 156 | $table = $table->where('tickets.dept_id', '=', $id); |
||
| 157 | } |
||
| 158 | |||
| 159 | return $table |
||
| 160 | ->Join('ticket_status', function ($join) { |
||
| 161 | $join->on('ticket_status.id', '=', 'tickets.status') |
||
| 162 | ->where('tickets.status', '=', 5); |
||
| 163 | }); |
||
| 164 | |||
| 165 | View Code Duplication | case '/ticket/answered': |
|
| 166 | if (Auth::user()->role == 'agent') { |
||
| 167 | $id = Auth::user()->primary_dpt; |
||
| 168 | $table = $table->where('tickets.dept_id', '=', $id); |
||
| 169 | } |
||
| 170 | |||
| 171 | return $table |
||
| 172 | ->Join('ticket_status', function ($join) { |
||
| 173 | $join->on('ticket_status.id', '=', 'tickets.status') |
||
| 174 | ->where('tickets.status', '=', 1) |
||
| 175 | ->where('tickets.isanswered', '=', 1); |
||
| 176 | }); |
||
| 177 | View Code Duplication | case '/ticket/assigned': |
|
| 178 | if (Auth::user()->role == 'agent') { |
||
| 179 | $id = Auth::user()->primary_dpt; |
||
| 180 | $table = $table->where('tickets.dept_id', '=', $id); |
||
| 181 | } |
||
| 182 | |||
| 183 | return $table |
||
| 184 | ->leftJoin('ticket_status', function ($join) { |
||
| 185 | $join->on('ticket_status.id', '=', 'tickets.status'); |
||
| 186 | }) |
||
| 187 | ->where('tickets.assigned_to', '>', 0) |
||
| 188 | ->where('tickets.status', '=', 1); |
||
| 189 | View Code Duplication | case '/ticket/open': |
|
| 190 | if (Auth::user()->role == 'agent') { |
||
| 191 | $id = Auth::user()->primary_dpt; |
||
| 192 | $table = $table->where('tickets.dept_id', '=', $id); |
||
| 193 | } |
||
| 194 | |||
| 195 | return $table |
||
| 196 | ->leftJoin('ticket_status', function ($join) { |
||
| 197 | $join->on('ticket_status.id', '=', 'tickets.status'); |
||
| 198 | }) |
||
| 199 | ->where('isanswered', '=', 0) |
||
| 200 | ->where('tickets.status', '=', 1); |
||
| 201 | case '/duetoday': |
||
| 202 | if (Auth::user()->role == 'agent') { |
||
| 203 | $id = Auth::user()->primary_dpt; |
||
| 204 | $table = $table->where('tickets.dept_id', '=', $id); |
||
| 205 | } |
||
| 206 | |||
| 207 | return $table |
||
| 208 | ->leftJoin('ticket_status', function ($join) { |
||
| 209 | $join->on('ticket_status.id', '=', 'tickets.status'); |
||
| 210 | }) |
||
| 211 | ->where('tickets.status', '=', 1) |
||
| 212 | |||
| 213 | ->whereNotNull('tickets.duedate') |
||
| 214 | ->whereDate('tickets.duedate', '=', \Carbon\Carbon::now()->format('Y-m-d')); |
||
| 215 | |||
| 216 | View Code Duplication | case '/ticket/followup': |
|
| 217 | if (Auth::user()->role == 'agent') { |
||
| 218 | $id = Auth::user()->primary_dpt; |
||
| 219 | $table = $table->where('tickets.dept_id', '=', $id); |
||
| 220 | } |
||
| 221 | |||
| 222 | return $table |
||
| 223 | ->leftJoin('ticket_status', function ($join) { |
||
| 224 | $join->on('ticket_status.id', '=', 'tickets.status'); |
||
| 225 | }) |
||
| 226 | ->where('tickets.status', '=', 1) |
||
| 227 | // ->where('tickets.isanswered', '=', 0) |
||
| 228 | ->where('tickets.follow_up', '=', 1); |
||
| 229 | } |
||
| 230 | } |
||
| 231 | |||
| 340 |