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

SkillDeclarationValidator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
eloc 27
dl 0
loc 48
ccs 0
cts 22
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A validator() 0 25 1
A validate() 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;
4
5
use Illuminate\Support\Facades\Validator;
6
use Illuminate\Validation\Rule;
7
use App\Models\Skill;
8
use App\Models\SkillDeclaration;
9
use App\Models\Lookup\SkillLevel;
10
use App\Models\Lookup\SkillStatus;
11
use App\Models\Applicant;
12
use App\Services\Validation\Rules\UniqueApplicantSkillRule;
13
14
class SkillDeclarationValidator
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class SkillDeclarationValidator
Loading history...
15
{
16
17
    protected $applicant;
18
    protected $skill_ids;
19
    protected $skill_status_ids;
20
    protected $skill_level_ids;
21
22
23
    public function __construct(Applicant $applicant)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
24
    {
25
        $this->applicant = $applicant;
26
        $this->skill_ids = Skill::all()->pluck('id');
27
        $this->skill_status_ids = SkillStatus::all()->pluck('id');
28
        $this->skill_level_ids = SkillLevel::all()->pluck('id');
29
30
    }
31
32
    public function validator(SkillDeclaration $skillDeclaration) {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function validator()
Loading history...
33
        $uniqueSkillRule = new UniqueApplicantSkillRule($this->applicant, $skillDeclaration->id);
34
35
        //Validate basic data is filled in
36
        $validator = Validator::make($skillDeclaration->getAttributes(), [
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
37
            'skill_id' => [
38
                'required',
39
                Rule::in($this->skill_ids->toArray()),
40
                $uniqueSkillRule,
41
            ],
42
            'applicant_id' => [
43
                'required',
44
                Rule::in([$this->applicant->id]),
45
            ],
46
            'skill_status_id' => [
47
                'required',
48
                Rule::in($this->skill_status_ids->toArray()),
49
            ],
50
            'skill_level_id' => [
51
                'required',
52
                Rule::in($this->skill_level_ids->toArray()),
53
            ],
54
            'description' => 'string|required',
55
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
56
        return $validator;
57
    }
58
59
    public function validate(SkillDeclaration $skillDeclaration)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function validate()
Loading history...
60
    {
61
        return $this->validator($skillDeclaration)->validate();
62
    }
63
64
65
}
66