SearchController::index()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 22
rs 9.2
cc 3
eloc 14
nc 3
nop 3
1
<?php
2
3
/*
4
 * rmarchiv.tk
5
 * (c) 2016-2017 by Marcel 'ryg' Hering
6
 */
7
8
namespace App\Http\Controllers;
9
10
use App\Models\Game;
11
use Illuminate\Http\Request;
12
use App\Helpers\DatabaseHelper;
13
14
class SearchController extends Controller
15
{
16
    public function index($orderby = 'title', $direction = 'asc', $query = '')
17
    {
18
        if ($query == '') {
19
            return view('search.index');
20
        } else {
21
            $rows = (\Auth::check()) ? \Auth::user()->settings->rows_per_page_games : config('app.rows_per_page_games');
22
23
            //$games = Game::search($query)->orderBy($orderby, $direction)->paginate($rows);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
24
25
            $games = Game::where('title', 'LIKE', '%'.$query.'%')
26
                ->orWhere('subtitle', 'LIKE', '%'.$query.'%')
27
                ->orderBy($orderby, $direction)->paginate($rows);
28
29
            return view('search.index', [
30
                'games'     => $games,
31
                'maxviews'  => DatabaseHelper::getGameViewsMax(),
32
                'term'      => $query,
33
                'orderby'   => $orderby,
34
                'direction' => $direction,
35
            ]);
36
        }
37
    }
38
39
    public function search(Request $request, $orderby = 'title', $direction = 'asc')
40
    {
41
        return redirect()->action('SearchController@index', [
42
            $orderby, $direction, $request->get('term'),
43
        ]);
44
    }
45
}
46