Completed
Push — master ( d6a5af...93636f )
by Iman
16s
created

CbValidator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 21
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A valid() 0 19 3
1
<?php
2
3
namespace crocodicstudio\crudbooster\helpers;
4
5
use Illuminate\Support\Facades\Validator;
6
7
class CbValidator
8
{
9
    public static function valid($rules = [], $type = 'json')
10
    {
11
        $validator = Validator::make(request()->all(), $rules);
12
13
        if (!$validator->fails()) {
14
            return true;
15
        }
16
17
        $message = $validator->errors()->all();
18
19
        if ($type == 'json') {
20
            $result = [];
21
            $result['api_status'] = 0;
22
            $result['api_message'] = implode(', ', $message);
23
            sendAndTerminate(response()->json($result, 200));
0 ignored issues
show
Bug introduced by
The method json() does not exist on Symfony\Component\HttpFoundation\Response. It seems like you code against a sub-type of Symfony\Component\HttpFoundation\Response such as Illuminate\Http\Response or Illuminate\Http\JsonResponse or Illuminate\Http\RedirectResponse. ( Ignorable by Annotation )

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

23
            sendAndTerminate(response()->/** @scrutinizer ignore-call */ json($result, 200));
Loading history...
24
        }
25
26
        $res = redirect()->back()->with(['message' => implode('<br/>', $message), 'message_type' => 'warning'])->withInput();
27
        sendAndTerminate($res);
28
    }
29
}