Passed
Branch dev (32180c)
by John
03:42
created

IndexController::index()   C

Complexity

Conditions 11
Paths 192

Size

Total Lines 35
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 31
c 0
b 0
f 0
nc 192
nop 1
dl 0
loc 35
rs 6.55

How to fix   Complexity   

Long Method

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:

1
<?php
2
3
namespace App\Http\Controllers\Contest;
4
5
use App\Models\ContestModel;
6
use App\Models\GroupModel;
7
use App\Http\Controllers\Controller;
8
use Illuminate\Http\Request;
9
use Auth;
10
use Redirect;
11
12
13
class IndexController extends Controller
14
{
15
    /**
16
     * Show the Contest Page.
17
     *
18
     * @return Response
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Contest\Response was not found. Did you mean Response? If so, make sure to prefix the type with \.
Loading history...
19
     */
20
    public function index(Request $request)
21
    {
22
        $all_data=$request->all();
23
        $contestModel=new ContestModel();
24
        $filter["rule"]=isset($all_data["rule"]) ? $all_data["rule"] : null;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$filter was never initialized. Although not strictly required by PHP, it is generally a good practice to add $filter = array(); before regardless.
Loading history...
25
        $filter["public"]=isset($all_data["public"]) ? $all_data["public"] : null;
26
        $filter["verified"]=isset($all_data["verified"]) ? $all_data["verified"] : null;
27
        $filter["rated"]=isset($all_data["rated"]) ? $all_data["rated"] : null;
28
        $filter["anticheated"]=isset($all_data["anticheated"]) ? $all_data["anticheated"] : null;
29
        $filter["practice"]=isset($all_data["practice"]) ? $all_data["practice"] : null;
30
        $return_list=$contestModel->list($filter,Auth::check()?Auth::user()->id:0);
31
        $featured=$contestModel->featured();
32
        if (is_null($return_list)) {
0 ignored issues
show
introduced by
The condition is_null($return_list) is always false.
Loading history...
33
            if (isset($all_data["page"]) && $all_data["page"]>1) {
34
                return redirect("/contest");
35
            } else {
36
                return view('contest.index', [
37
                    'page_title'=>"Contest",
38
                    'site_title'=>config("app.name"),
39
                    'navigation' => "Contest",
40
                    'contest_list'=> null,
41
                    'paginator' => null,
42
                    'featured'=>$featured,
43
                    'filter' => $filter
44
                ]);
45
            }
46
        } else {
47
            return view('contest.index', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('contest.ind..., 'filter' => $filter)) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
48
                'page_title'=>"Contest",
49
                'site_title'=>config("app.name"),
50
                'navigation' => "Contest",
51
                'contest_list'=>$return_list['contents'],
52
                'paginator' => $return_list['paginator'],
53
                'featured'=>$featured,
54
                'filter' => $filter
55
            ]);
56
        }
57
    }
58
59
    /**
60
     * Show the Contest Detail Page.
61
     *
62
     * @return Response
63
     */
64
    public function detail($cid)
65
    {
66
        $contestModel=new ContestModel();
67
        $groupModel=new GroupModel();
68
        $clearance=Auth::check() ? $contestModel->judgeClearance($cid, Auth::user()->id) : 0;
69
        if (Auth::check()) {
70
            $contest_detail=$contestModel->detail($cid, Auth::user()->id);
71
            $registration=$contestModel->registration($cid, Auth::user()->id);
72
            $inGroup=$groupModel->isMember($contest_detail["data"]["contest_detail"]["gid"], Auth::user()->id);
73
        } else {
74
            $contest_detail=$contestModel->detail($cid);
75
            $registration=[];
76
            $inGroup=false;
77
        }
78
        if ($contest_detail["ret"]!=200) {
79
            return Redirect::route('contest.index');
0 ignored issues
show
Bug Best Practice introduced by
The expression return Redirect::route('contest.index') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
80
        }
81
        return view('contest.detail', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('contest.det...'inGroup' => $inGroup)) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Contest\Response.
Loading history...
82
            'page_title'=>"Contest",
83
            'site_title'=>config("app.name"),
84
            'navigation' => "Contest",
85
            'detail'=>$contest_detail["data"]["contest_detail"],
86
            'clearance' => $clearance,
87
            'registration' => $registration,
88
            'inGroup' => $inGroup
89
        ]);
90
    }
91
}
92