Passed
Pull Request — master (#75)
by
unknown
04:18
created

SearchController::__invoke()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 12
nc 4
nop 1
dl 0
loc 17
rs 9.8666
c 0
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\Ajax;
4
5
use App\Http\Controllers\Controller;
6
use App\Models\ResponseModel;
7
use App\Models\ProblemModel;
8
use Illuminate\Http\Request;
9
use Illuminate\Http\Response;
10
use Illuminate\Support\Facades\Validator;
11
12
class SearchController extends Controller
13
{
14
    /**
15
     * The Ajax to Search Problem using Problem code.
16
     *
17
     * @param Request $request web request
18
     *
19
     * @return Response
20
     */
21
    public function __invoke(Request $request)
22
    {
23
        if(!$request->has('search_key')){
24
            return ResponseModel::err(1003);
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Models\ResponseModel::err(1003) returns the type Illuminate\Http\JsonResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
25
        }
26
27
        $search_key = strtoupper($request->input('search_key'));
28
        $problem=new ProblemModel();
29
        $prob_details = $problem->detail($search_key);
30
        if(!is_null($prob_details)){
31
            if ($problem->isBlocked($prob_details["pid"])) {
32
                return ResponseModel::err(403);
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Models\ResponseModel::err(403) returns the type Illuminate\Http\JsonResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
33
            }
34
            $problem_url = route('problem_detail',['pcode' => $search_key]);
35
            return ResponseModel::success(200, null, $problem_url);
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Models\Respon...00, null, $problem_url) returns the type Illuminate\Http\JsonResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
36
        }else{
37
            return ResponseModel::err(3001);
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Models\ResponseModel::err(3001) returns the type Illuminate\Http\JsonResponse which is incompatible with the documented return type Illuminate\Http\Response.
Loading history...
38
        }
39
    }
40
}
41