Passed
Push — master ( 4bf123...27c321 )
by John
06:11
created

ProblemController   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 125
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 76
dl 0
loc 125
rs 10
c 0
b 0
f 0
wmc 17

4 Methods

Rating   Name   Duplication   Size   Complexity  
B index() 0 34 6
A detail() 0 12 3
A editor() 0 36 5
A solution() 0 12 3
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Models\ProblemModel;
6
use App\Models\SubmissionModel;
7
use App\Models\CompilerModel;
8
use App\Http\Controllers\Controller;
9
use Illuminate\Http\Request;
10
use JavaScript;
11
use Auth;
12
13
class ProblemController extends Controller
14
{
15
    /**
16
     * Show the Problem Index Page.
17
     *
18
     * @return Response
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\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
        $problem=new ProblemModel();
24
        $filter["oj"]=isset($all_data["oj"]) ? $all_data["oj"] : 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["tag"]=isset($all_data["tag"]) ? $all_data["tag"] : null;
26
        $list_return=$problem->list($filter);
27
        $tags=$problem->tags();
28
        $ojs=$problem->ojs();
29
        if (is_null($list_return)) {
30
            if (isset($all_data["page"]) && $all_data["page"]>1) {
31
                return redirect("/problem");
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect('/problem') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
32
            } else {
33
                return view('problem.index', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('problem.ind..., 'filter' => $filter)) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
34
                    'page_title' => "Problem",
35
                    'site_title' => "NOJ",
36
                    'navigation' => "Problem",
37
                    'prob_list' => null,
38
                    'prob_paginate' => null,
39
                    'tags' => $tags,
40
                    'ojs' => $ojs,
41
                    'filter' => $filter
42
                ]);
43
            }
44
        } else {
45
            return view('problem.index', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('problem.ind..., 'filter' => $filter)) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
46
                'page_title' => "Problem",
47
                'site_title' => "NOJ",
48
                'navigation' => "Problem",
49
                'prob_list' => $list_return['problems'],
50
                'paginator' => $list_return['paginator'],
51
                'tags' => $tags,
52
                'ojs' => $ojs,
53
                'filter' => $filter
54
            ]);
55
        }
56
    }
57
    /**
58
     * Show the Problem Detail Page.
59
     *
60
     * @return Response
61
     */
62
    public function detail($pcode)
63
    {
64
        $problem=new ProblemModel();
65
        $prob_detail=$problem->detail($pcode);
66
        if ($problem->isBlocked($prob_detail["pid"])) {
67
            return abort('403');
0 ignored issues
show
Bug introduced by
Are you sure the usage of abort('403') is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug Best Practice introduced by
The expression return abort('403') returns the type void which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
68
        }
69
        return is_null($prob_detail) ?  redirect("/problem") : view('problem.detail', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return is_null($prob_det...tail' => $prob_detail)) returns the type Illuminate\Http\Redirect...se|Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
70
                                            'page_title'=>$prob_detail["title"],
71
                                            'site_title'=>"NOJ",
72
                                            'navigation' => "Problem",
73
                                            'detail' => $prob_detail
74
                                        ]);
75
    }
76
77
    /**
78
     * Show the Problem Solution Page.
79
     *
80
     * @return Response
81
     */
82
    public function solution($pcode)
83
    {
84
        $problem=new ProblemModel();
85
        $prob_detail=$problem->detail($pcode);
86
        if ($problem->isBlocked($prob_detail["pid"])) {
87
            return abort('403');
0 ignored issues
show
Bug introduced by
Are you sure the usage of abort('403') is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug Best Practice introduced by
The expression return abort('403') returns the type void which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
88
        }
89
        return is_null($prob_detail) ?  redirect("/problem") : view('problem.solution', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return is_null($prob_det...tail' => $prob_detail)) returns the type Illuminate\Http\Redirect...se|Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
90
                                            'page_title'=> "Solution",
91
                                            'site_title'=>"NOJ",
92
                                            'navigation' => $prob_detail["title"],
93
                                            'detail' => $prob_detail
94
                                        ]);
95
    }
96
97
    /**
98
     * Show the Problem Editor Page.
99
     *
100
     * @return Response
101
     */
102
    public function editor($pcode)
103
    {
104
        $problem=new ProblemModel();
105
        $compiler=new CompilerModel();
106
        $submission=new SubmissionModel();
107
        $prob_detail=$problem->detail($pcode);
108
        if ($problem->isBlocked($prob_detail["pid"])) {
109
            return abort('403');
0 ignored issues
show
Bug Best Practice introduced by
The expression return abort('403') returns the type void which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
Bug introduced by
Are you sure the usage of abort('403') is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
110
        }
111
        $compiler_list=$compiler->list($prob_detail["OJ"], $prob_detail["pid"]);
112
        $prob_status=$submission->getProblemStatus($prob_detail["pid"], Auth::user()->id);
113
114
        $compiler_pref=$compiler->pref($compiler_list, $prob_detail["pid"], Auth::user()->id);
115
        $pref=$compiler_pref["pref"];
116
        $submit_code=$compiler_pref["code"];
117
118
        $oj_detail=$problem->ojdetail($prob_detail["OJ"]);
119
120
        if (empty($prob_status)) {
121
            $prob_status=[
122
                "verdict"=>"NOT SUBMIT",
123
                "color"=>""
124
            ];
125
        }
126
127
        return is_null($prob_detail) ?  redirect("/problem") : view('problem.editor', [
0 ignored issues
show
Bug Best Practice introduced by
The expression return is_null($prob_det...detail' => $oj_detail)) returns the type Illuminate\Http\Redirect...se|Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
128
                                            'page_title'=>$prob_detail["title"],
129
                                            'site_title'=>"NOJ",
130
                                            'navigation' => "Problem",
131
                                            'detail' => $prob_detail,
132
                                            'compiler_list' => $compiler_list,
133
                                            'status' => $prob_status,
134
                                            'pref'=>$pref<0 ? 0 : $pref,
135
                                            'submit_code'=>$submit_code,
136
                                            'contest_mode'=> false,
137
                                            'oj_detail'=>$oj_detail
138
                                        ]);
139
    }
140
}
141