| Conditions | 10 |
| Paths | 24 |
| Total Lines | 37 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 17 | public function index(Request $request) |
||
| 18 | { |
||
| 19 | $query = Source::query()->with(['publication', 'repositories', 'author', 'type']); |
||
| 20 | |||
| 21 | if ($request->has('searchTerm')) { |
||
| 22 | $columnsToSearch = ['titl', 'sour', 'auth', 'data', 'text', 'publ', 'abbr', 'name', 'description', 'repository_id', 'author_id', 'publication_id', 'type_id', 'is_active', 'group', 'quay', 'page']; |
||
| 23 | $search_term = json_decode($request->searchTerm)->searchTerm; |
||
| 24 | if (! empty($search_term)) { |
||
| 25 | $searchQuery = '%'.$search_term.'%'; |
||
| 26 | foreach ($columnsToSearch as $column) { |
||
| 27 | $query->orWhere($column, 'LIKE', $searchQuery); |
||
| 28 | } |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | if ($request->has('columnFilters')) { |
||
| 33 | $filters = get_object_vars(json_decode($request->columnFilters)); |
||
| 34 | $relationship_column = ['repositories.name', 'author.name', 'publication.name', 'type.name']; |
||
| 35 | foreach ($filters as $key => $value) { |
||
| 36 | if (! in_array($key, $relationship_column)) { |
||
| 37 | if (! empty($value)) { |
||
| 38 | $query->orWhere($key, 'like', '%'.$value.'%'); |
||
| 39 | } |
||
| 40 | } |
||
| 41 | } |
||
| 42 | } |
||
| 43 | |||
| 44 | if ($request->has('sort.0')) { |
||
| 45 | $sort = json_decode($request->sort[0]); |
||
| 46 | $query->orderBy($sort->field, $sort->type); |
||
| 47 | } |
||
| 48 | |||
| 49 | if ($request->has('perPage')) { |
||
| 50 | $rows = $query->paginate($request->perPage); |
||
| 51 | } |
||
| 52 | |||
| 53 | return $rows; |
||
|
|
|||
| 54 | } |
||
| 198 |