Completed
Push — master ( 52970f...c6d773 )
by Tristan
24:57 queued 10:40
created

UpdateReferenceValidator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
eloc 23
dl 0
loc 68
ccs 0
cts 16
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
use App\Services\Validation\Rules\SkillDeclarationBelongsToUserRule;
12
13
class UpdateReferenceValidator extends BaseDataValidator implements DataValidator
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class UpdateReferenceValidator
Loading history...
14
{
15
16
    /**
17
     * Array of all possible relationship ids.
18
     *
19
     * @var int[]
20
     */
21
    protected $relationshipIds;
22
23
    /**
24
     * Array of all possible skill ids.
25
     *
26
     * @var int[]
27
     */
28
    protected $skillIds;
29
30
    /**
31
     * Construct a new UpdateReferenceValidator
32
     */
33
    public function __construct()
34
    {
35
        $this->relationshipIds = Relationship::all()->pluck('id')->toArray();
36
        $this->skillIds = Skill::all()->pluck('id')->toArray();
37
    }
38
    /**
39
     * Get the validation rules that apply to the request.
40
     *
41
     * @return mixed[]
42
     */
43
    public function rules() : array
44
    {
45
        return [
46
            'name' => 'required|string|max:191',
47
            'email' => [
48
                'required',
49
                'string',
50
                'max:191',
51
                'email',
52
            ],
53
            'relationship_id' => [
54
                'required',
55
                Rule::in($this->relationshipIds)
56
            ],
57
            'description' => 'required|string',
58
59
            'relatives.skills.*.id' => [
60
                'required',
61
                new SkillDeclarationBelongsToUserRule
62
            ],
63
64
            'projects.*.name' => 'required|string|max:191',
65
            'projects.*.start_date' => 'required|date',
66
            'projects.*.end_date' => 'required|date',
67
68
69
        ];
70
    }
71
72
    /**
73
     * Returns a validator made with this data
74
     *
75
     * @param  mixed[] $data Data to validate.
76
     * @return Validator
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
77
     */
78
    public function validator(array $data) : \Illuminate\Validation\Validator
79
    {
80
        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...
81
    }
82
}
83