Passed
Push — master ( b3147e...c49c81 )
by Ferry
03:13
created

SelectController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 14
dl 0
loc 21
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A postLookup() 0 19 5
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: User
5
 * Date: 5/10/2019
6
 * Time: 10:38 PM
7
 */
8
9
namespace crocodicstudio\crudbooster\types\select;
10
11
use Illuminate\Routing\Controller as BaseController;
12
use Illuminate\Support\Facades\DB;
13
14
class SelectController extends BaseController
15
{
16
    public function postLookup() {
17
        $foreignKey = decrypt(request('foreign_key'));
0 ignored issues
show
Bug introduced by
It seems like request('foreign_key') can also be of type array; however, parameter $value of decrypt() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

17
        $foreignKey = decrypt(/** @scrutinizer ignore-type */ request('foreign_key'));
Loading history...
18
        $foreignValue = request('foreign_value');
19
        $table = decrypt(request('table'));
20
        $sqlCondition = decrypt(request('sql_condition'));
21
        if($foreignKey && $foreignValue && $table) {
22
23
            $data = DB::table($table)
24
                ->where($foreignKey, $foreignValue);
25
            if($sqlCondition) {
26
                $data->whereRaw($sqlCondition);
27
            }
28
29
            $data = $data->get();
30
31
            return response()->json(['status'=>true, 'data'=>$data]);
32
33
        }else{
34
            return response()->json(['status'=>false]);
35
        }
36
    }
37
}