| Conditions | 25 |
| Paths | 9216 |
| Total Lines | 92 |
| 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 |
||
| 21 | public function index(Request $request) |
||
| 22 | { |
||
| 23 | ini_set('memory_limit', '-1'); |
||
| 24 | ini_set('max_execution_time', '0'); |
||
| 25 | |||
| 26 | $query = ApiAccessLogs::query(); |
||
| 27 | |||
| 28 | $uid = $request->input('uid'); |
||
| 29 | if (isset($uid) && $uid) |
||
| 30 | { |
||
| 31 | $query = $query->where('user.id', $uid); |
||
| 32 | } |
||
| 33 | |||
| 34 | $method = $request->input('method'); |
||
| 35 | if (isset($method) && $method) |
||
| 36 | { |
||
| 37 | $query = $query->where('request_method', $method); |
||
| 38 | } |
||
| 39 | |||
| 40 | $project_key = $request->input('project_key'); |
||
| 41 | if (isset($project_key) && $project_key) |
||
| 42 | { |
||
| 43 | $query = $query->where('project_key', $project_key); |
||
| 44 | } |
||
| 45 | |||
| 46 | $module = $request->input('module'); |
||
| 47 | if (isset($module) && $module) |
||
| 48 | { |
||
| 49 | $query = $query->where('module', $module); |
||
| 50 | } |
||
| 51 | |||
| 52 | $request_time = $request->input('request_time'); |
||
| 53 | if (isset($request_time) && $request_time) |
||
| 54 | { |
||
| 55 | if (strpos($request_time, '~') !== false) |
||
| 56 | { |
||
| 57 | $sections = explode('~', $request_time); |
||
| 58 | if ($sections[0]) |
||
| 59 | { |
||
| 60 | $query->where('requested_start_at', '>=', strtotime($sections[0]) * 1000); |
||
| 61 | } |
||
| 62 | if ($sections[1]) |
||
| 63 | { |
||
| 64 | $query->where('requested_start_at', '<=', strtotime($sections[1] . ' 23:59:59') * 1000); |
||
| 65 | } |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | $url = $request->input('request_url'); |
||
| 70 | if (isset($url) && $url) |
||
| 71 | { |
||
| 72 | $query->where('request_url', 'like', '%' . $url . '%'); |
||
| 73 | } |
||
| 74 | |||
| 75 | $request_source_ip = $request->input('request_source_ip'); |
||
| 76 | if (isset($request_source_ip) && $request_source_ip) |
||
| 77 | { |
||
| 78 | $query->where('request_source_ip', $request_source_ip); |
||
| 79 | } |
||
| 80 | |||
| 81 | $exec_time = $request->input('exec_time'); |
||
| 82 | if (isset($exec_time) && $exec_time) |
||
| 83 | { |
||
| 84 | $flag = substr($exec_time, 0, 1); |
||
| 85 | if ($flag == '-') |
||
| 86 | { |
||
| 87 | $query->where('exec_time', '<=', abs(floatval($exec_time)) * 1000); |
||
| 88 | } |
||
| 89 | else |
||
| 90 | { |
||
| 91 | $query->where('exec_time', '>=', abs(floatval($exec_time)) * 1000); |
||
| 92 | } |
||
| 93 | } |
||
| 94 | |||
| 95 | // get total |
||
| 96 | $total = $query->count(); |
||
| 97 | $query->orderBy('_id', 'desc'); |
||
| 98 | $page_size = $request->input('limit') ? intval($request->input('limit')) : 100; |
||
| 99 | $page = $request->input('page') ?: 1; |
||
| 100 | $query = $query->skip($page_size * ($page - 1))->take($page_size); |
||
| 101 | |||
| 102 | $logs = $query->get(); |
||
| 103 | |||
| 104 | $from = $request->input('from'); |
||
| 105 | if (isset($from) && $from == 'export') |
||
| 106 | { |
||
| 107 | $this->export($logs); |
||
| 108 | exit(); |
||
| 109 | } |
||
| 110 | |||
| 111 | return Response()->json([ 'ecode' => 0, 'data' => $logs, 'options' => [ 'total' => $total, 'sizePerPage' => $page_size ] ]); |
||
|
|
|||
| 112 | } |
||
| 113 | |||
| 160 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: