Passed
Push — develop ( 3db2fb...b27e40 )
by Septianata
05:11
created

FormRequest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Test Coverage

Coverage 50%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 12
c 1
b 0
f 0
dl 0
loc 71
ccs 8
cts 16
cp 0.5
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A createValidator() 0 8 1
A getRules() 0 3 1
A authorize() 0 3 1
A attributes() 0 3 1
A rules() 0 3 1
A getAttributes() 0 3 1
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
abstract class FormRequest extends BaseFormRequest
11
{
12
    /**
13
     * Determine if the user is authorized to make this request.
14
     *
15
     * @return bool
16
     */
17 5
    public function authorize()
18
    {
19 5
        return true;
20
    }
21
22
    /**
23
     * Get the validation rules that apply to the request.
24
     *
25
     * @return array
26
     */
27 1
    public function rules()
28
    {
29 1
        return static::getRules();
30
    }
31
32
    /**
33
     * Get the validation rules that apply to the request in static way.
34
     *
35
     * @return array
36
     */
37
    public static function getRules()
38
    {
39
        return [
40
            //
41
        ];
42
    }
43
44
    /**
45
     * {@inheritDoc}
46
     */
47 2
    public function attributes()
48
    {
49 2
        return static::getAttributes();
50
    }
51
52
    /**
53
     * Get custom attributes for validator errors in static way.
54
     *
55
     * @return array
56
     */
57 1
    public static function getAttributes()
58
    {
59
        return [
60
            //
61 1
        ];
62
    }
63
64
    /**
65
     * Create the validator instance based on the given field name.
66
     *
67
     * @param  mixed  $data
68
     * @param  string  $field
69
     * @param  array  $messages
70
     * @param  bool  $stopOnFirstFailure
71
     * @return \Illuminate\Contracts\Validation\Validator
72
     */
73
    public static function createValidator($data, string $field, array $messages = [], bool $stopOnFirstFailure = false): ValidationFactory
74
    {
75
        return Validator::make(
76
            [$field => $data],
77
            Arr::only(static::getRules(), $field),
78
            $messages,
79
            Arr::only(static::getAttributes(), $field)
80
        )->stopOnFirstFailure($stopOnFirstFailure);
81
    }
82
}
83