Passed
Push — master ( d2b921...2f72d9 )
by John
04:17
created

SubmissionController::share()   B

Complexity

Conditions 8
Paths 6

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 16
nc 6
nop 1
dl 0
loc 23
rs 8.4444
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\Ajax;
4
5
use App\Models\ProblemModel;
6
use App\Models\SubmissionModel;
7
use App\Models\ResponseModel;
8
use App\Models\CompilerModel;
9
use App\Http\Controllers\VirtualJudge\Submit;
10
use App\Http\Controllers\VirtualJudge\Judge;
11
use App\Http\Controllers\Controller;
12
use Illuminate\Http\Request;
13
use Illuminate\Http\Response;
14
use App\Http\Controllers\VirtualCrawler\Crawler;
15
use App\Jobs\ProcessSubmission;
16
use Illuminate\Support\Facades\Validator;
17
use Auth;
18
19
class SubmissionController extends Controller
20
{
21
    /**
22
     * The Ajax Submission Detail.
23
     *
24
     * @param Request $request web request
25
     *
26
     * @return Response
27
     */
28
    public function detail(Request $request)
29
    {
30
        $all_data=$request->all();
31
        $validator=Validator::make($all_data, [
32
            'sid' => 'required|integer',
33
        ]);
34
        if ($validator->fails()) {
35
            return ResponseModel::err(3002);
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Models\ResponseModel::err(3002) returns the type Illuminate\Http\JsonResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
36
        }
37
        $submission=new SubmissionModel();
38
        $status=$submission->getJudgeStatus($all_data["sid"], Auth::check() ? Auth::user()->id : null);
39
        return ResponseModel::success(200, null, $status);
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Models\Respon...ess(200, null, $status) returns the type Illuminate\Http\JsonResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
40
    }
41
42
    /**
43
     * The Ajax Submission Detail.
44
     *
45
     * @param Request $request web request
46
     *
47
     * @return Response
48
     */
49
    public function share(Request $request)
50
    {
51
        $all_data=$request->all();
52
        $validator=Validator::make($all_data, [
53
            'sid' => 'required|integer',
54
            'method' => 'required|integer',
55
        ]);
56
        if ($validator->fails()) {
57
            return ResponseModel::err(3002);
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Models\ResponseModel::err(3002) returns the type Illuminate\Http\JsonResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
58
        }
59
        $submissionModel=new SubmissionModel();
60
        if($all_data["method"]==1){
61
            // NOJ Share
62
            $status=$submissionModel->share($all_data["sid"], Auth::check() ? Auth::user()->id : null);
63
            return empty($status)?ResponseModel::err(1001):ResponseModel::success(200, null, $status);
0 ignored issues
show
Bug Best Practice introduced by
The expression return empty($status) ? ...ess(200, null, $status) returns the type Illuminate\Http\JsonResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
64
        } elseif($all_data["method"]==2){
65
            // Pastebin
66
            $status=$submissionModel->sharePB($all_data["sid"], Auth::check() ? Auth::user()->id : null);
67
            return empty($status)?ResponseModel::err(1001):ResponseModel::success(200, null, $status);
0 ignored issues
show
Bug Best Practice introduced by
The expression return empty($status) ? ...ess(200, null, $status) returns the type Illuminate\Http\JsonResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
68
        } else {
69
            return ResponseModel::err(6002);
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Models\ResponseModel::err(6002) returns the type Illuminate\Http\JsonResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
70
        }
71
        return ResponseModel::success(200, null, $status);
0 ignored issues
show
Unused Code introduced by
return App\Models\Respon...ess(200, null, $status) is not reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
72
    }
73
}
74