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

UpdateWorkSampleValidator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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\FileType;
10
use App\Models\Skill;
11
12
class UpdateWorkSampleValidator extends BaseDataValidator implements DataValidator
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class UpdateWorkSampleValidator
Loading history...
13
{
14
15
    /**
16
     * Array of all possible FileType ids.
17
     *
18
     * @var int[]
19
     */
20
    protected $fileTypeIds;
21
22
    /**
23
     * Array of all possible skill ids.
24
     *
25
     * @var int[]
26
     */
27
    protected $skillIds;
28
29
    /**
30
     * Construct a new UpdateWorkSampleValidator
31
     */
32
    public function __construct()
33
    {
34
        $this->fileTypeIds = FileType::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
            'file_type_id' => [
48
                'required',
49
                Rule::in($this->fileTypeIds)
50
            ],
51
            'url' => 'required|url',
52
            'description' => 'required|string',
53
            'relatives.skills.*.id' => [
54
                'required',
55
                Rule::in($this->skillIds)
56
            ],
57
        ];
58
    }
59
60
    /**
61
     * Returns a validator made with this data
62
     *
63
     * @param  mixed[] $data Data to validate.
64
     * @return Validator
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
65
     */
66
    public function validator(array $data) : \Illuminate\Validation\Validator
67
    {
68
        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...
69
    }
70
}
71