FormRequest::authorize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace App\Infrastructure\Foundation\Http;
4
5
use Illuminate\Contracts\Validation\Validator as ValidationFactory;
6
use Illuminate\Foundation\Http\FormRequest as BaseFormRequest;
7
use Illuminate\Support\Arr;
8
use Illuminate\Support\Facades\Validator;
9
10
/**
11
 * @method \App\Models\User|null user() Get the user making the request.
12
 */
13
abstract class FormRequest extends BaseFormRequest
14
{
15
    /**
16
     * Determine if the user is authorized to make this request.
17
     *
18
     * @return bool
19
     */
20
    public function authorize()
21
    {
22
        return true;
23
    }
24
25
    /**
26
     * Get the validation rules that apply to the request.
27
     *
28
     * @return array
29
     */
30
    public function rules()
31
    {
32
        return static::getRules();
33
    }
34
35
    /**
36
     * Get the validation rules that apply to the request in static way.
37
     *
38
     * @return array
39
     */
40
    public static function getRules()
41
    {
42
        return [
43
            //
44
        ];
45
    }
46
47
    /**
48
     * {@inheritDoc}
49
     */
50
    public function attributes()
51
    {
52
        return static::getAttributes();
53
    }
54
55
    /**
56
     * Get custom attributes for validator errors in static way.
57
     *
58
     * @return array
59
     */
60
    public static function getAttributes()
61
    {
62
        return [
63
            //
64
        ];
65
    }
66
67
    /**
68
     * Create the validator instance based on the given field name.
69
     *
70
     * @param  mixed  $data
71
     * @param  string  $field
72
     * @param  array  $messages
73
     * @param  bool  $stopOnFirstFailure
74
     * @return \Illuminate\Contracts\Validation\Validator
75
     */
76
    public static function createValidator($data, string $field, array $messages = [], bool $stopOnFirstFailure = false): ValidationFactory
77
    {
78
        return Validator::make(
79
            [$field => $data],
80
            Arr::only(static::getRules(), $field),
81
            $messages,
82
            Arr::only(static::getAttributes(), $field)
83
        )->stopOnFirstFailure($stopOnFirstFailure);
84
    }
85
}
86