Passed
Push — feature/ajax_ref_and_projects ( edf85c...426ffa )
by Tristan
09:48
created

UpdateReferenceValidator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
eloc 19
dl 0
loc 67
ccs 0
cts 12
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 24 1
A __construct() 0 4 1
A validator() 0 3 1
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace App\Services\Validation\Requests;
4
5
use App\Services\Validation\BaseDataValidator;
6
use App\Services\Validation\Contracts\DataValidator;
7
use Illuminate\Support\Facades\Validator;
8
use Illuminate\Validation\Rule;
9
use App\Models\Lookup\Relationship;
10
use App\Models\Skill;
11
12
class UpdateReferenceValidator extends BaseDataValidator implements DataValidator
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class UpdateReferenceValidator
Loading history...
13
{
14
15
    /**
16
     * Array of all possible relationship ids.
17
     *
18
     * @var int[]
19
     */
20
    protected $relationshipIds;
21
22
    /**
23
     * Array of all possible skill ids.
24
     *
25
     * @var int[]
26
     */
27
    protected $skillIds;
28
29
    /**
30
     * Construct a new UpdateReferenceValidator
31
     */
32
    public function __construct()
33
    {
34
        $this->relationshipIds = Relationship::all()->pluck('id')->toArray();
35
        $this->skillIds = Skill::all()->pluck('id')->toArray();
36
    }
37
    /**
38
     * Get the validation rules that apply to the request.
39
     *
40
     * @return mixed[]
41
     */
42
    public function rules() : array
43
    {
44
        return [
45
            // Name validation
46
            'name' => 'required|string|max:191',
47
48
            // Email validation
49
            'email' => [
50
                'required',
51
                'string',
52
                'max:191',
53
                'email',
54
            ],
55
56
            //Relationship Id validation
57
            'relationship_id' => [
58
                'required',
59
                Rule::in($this->relationshipIds)
60
            ],
61
62
            'description' => 'required|string',
63
64
            'relatives.skills.*.id' => [
65
                Rule::in($this->skillIds)
66
            ],
67
        ];
68
    }
69
70
    /**
71
     * Returns a validator made with this data
72
     *
73
     * @param  mixed[] $data Data to validate.
74
     * @return Validator
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
75
     */
76
    public function validator(array $data) : \Illuminate\Validation\Validator
77
    {
78
        return Validator::make($data, $this->rules());
0 ignored issues
show
Bug Best Practice introduced by
The expression return Illuminate\Suppor...($data, $this->rules()) returns the type Illuminate\Contracts\Validation\Validator which includes types incompatible with the type-hinted return Illuminate\Validation\Validator.
Loading history...
79
    }
80
}
81