Passed
Push — task/talent-dot-test ( 0ef1e8...074f28 )
by Grant
08:57 queued 03:14
created

UpdateReferenceValidator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 21
dl 0
loc 60
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A rules() 0 24 1
A __construct() 0 3 1
A validator() 0 3 1
1
<?php
2
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\Services\Validation\Rules\SkillDeclarationBelongsToUserRule;
11
12
class UpdateReferenceValidator extends BaseDataValidator implements DataValidator
13
{
14
15
    /**
16
     * Array of all possible relationship ids.
17
     *
18
     * @var int[]
19
     */
20
    protected $relationshipIds;
21
22
    /**
23
     * Construct a new UpdateReferenceValidator
24
     */
25 2
    public function __construct()
26
    {
27 2
        $this->relationshipIds = Relationship::all()->pluck('id')->toArray();
28 2
    }
29
    /**
30
     * Get the validation rules that apply to the request.
31
     *
32
     * @return mixed[]
33
     */
34 2
    public function rules() : array
35
    {
36
        return [
37 2
            'name' => 'required|string|max:191',
38
            'email' => [
39
                'required',
40
                'string',
41
                'max:191',
42
                'email',
43
            ],
44
            'relationship_id' => [
45 2
                'required',
46 2
                Rule::in($this->relationshipIds)
47
            ],
48 2
            'description' => 'required|string',
49
50
            'relatives.skills.*.id' => [
51 2
                'required',
52 2
                new SkillDeclarationBelongsToUserRule
53
            ],
54
55 2
            'projects.*.name' => 'required|string|max:191',
56 2
            'projects.*.start_date' => 'required|date',
57 2
            'projects.*.end_date' => 'required|date',
58
59
60
        ];
61
    }
62
63
    /**
64
     * Returns a validator made with this data
65
     *
66
     * @param  mixed[] $data Data to validate.
67
     * @return Validator
68
     */
69 2
    public function validator(array $data) : \Illuminate\Validation\Validator
70
    {
71 2
        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...
72
    }
73
}
74