Conditions | 10 |
Paths | 24 |
Total Lines | 37 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | 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 |
||
16 | public function index(Request $request) |
||
17 | { |
||
18 | $query = Subm::query()->with('addr'); |
||
19 | |||
20 | if ($request->has('searchTerm')) { |
||
21 | $columnsToSearch = ['group', 'name', 'addr_id', 'rin', 'rfn', 'lang', 'email', 'phon', 'fax', 'www']; |
||
22 | $search_term = json_decode($request->searchTerm)->searchTerm; |
||
23 | if (! empty($search_term)) { |
||
24 | $searchQuery = '%'.$search_term.'%'; |
||
25 | foreach ($columnsToSearch as $column) { |
||
26 | $query->orWhere($column, 'LIKE', $searchQuery); |
||
27 | } |
||
28 | } |
||
29 | } |
||
30 | |||
31 | if ($request->has('columnFilters')) { |
||
32 | $filters = get_object_vars(json_decode($request->columnFilters)); |
||
33 | $relationship_column = ['addr.adr2']; |
||
34 | foreach ($filters as $key => $value) { |
||
35 | if (! in_array($key, $relationship_column)) { |
||
36 | if (! empty($value)) { |
||
37 | $query->orWhere($key, 'like', '%'.$value.'%'); |
||
38 | } |
||
39 | } |
||
40 | } |
||
41 | } |
||
42 | |||
43 | if ($request->has('sort.0')) { |
||
44 | $sort = json_decode($request->sort[0]); |
||
45 | $query->orderBy($sort->field, $sort->type); |
||
46 | } |
||
47 | |||
48 | if ($request->has('perPage')) { |
||
49 | $rows = $query->paginate($request->perPage); |
||
50 | } |
||
51 | |||
52 | return $rows; |
||
|
|||
53 | } |
||
160 |