Passed
Push — feature/job-builder/step-03-ui ( dabf2e...dabf2e )
by Xander
20:05 queued 13s
created

SkillDeclarationValidator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A validator() 0 25 1
A __construct() 0 6 1
A validate() 0 3 1
1
<?php
2
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
15
{
16
17
    protected $applicant;
1 ignored issue
show
introduced by
Property \App\Services\Validation\SkillDeclarationValidator::$applicant does not have @var annotation.
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
18
    protected $skill_ids;
1 ignored issue
show
introduced by
Property \App\Services\Validation\SkillDeclarationValidator::$skill_ids does not have @var annotation.
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
19
    protected $skill_status_ids;
1 ignored issue
show
introduced by
Property \App\Services\Validation\SkillDeclarationValidator::$skill_status_ids does not have @var annotation.
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
20
    protected $skill_level_ids;
1 ignored issue
show
introduced by
Property \App\Services\Validation\SkillDeclarationValidator::$skill_level_ids does not have @var annotation.
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
21
22
23 1
    public function __construct(Applicant $applicant)
1 ignored issue
show
Coding Style Documentation introduced by
Missing doc comment for function __construct()
Loading history...
24
    {
25 1
        $this->applicant = $applicant;
26 1
        $this->skill_ids = Skill::all()->pluck('id');
27 1
        $this->skill_status_ids = SkillStatus::all()->pluck('id');
28 1
        $this->skill_level_ids = SkillLevel::all()->pluck('id');
29
30 1
    }
0 ignored issues
show
Coding Style introduced by
Function closing brace must go on the next line following the body; found 1 blank lines before brace
Loading history...
31
32 1
    public function validator(SkillDeclaration $skillDeclaration) {
1 ignored issue
show
introduced by
Method \App\Services\Validation\SkillDeclarationValidator::validator() does not have return type hint nor @return annotation for its return value.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function validator()
Loading history...
33 1
        $uniqueSkillRule = new UniqueApplicantSkillRule($this->applicant, $skillDeclaration->id);
34
35
        //Validate basic data is filled in
0 ignored issues
show
Coding Style introduced by
No space found before comment text; expected "// Validate basic data is filled in" but found "//Validate basic data is filled in"
Loading history...
36 1
        $validator = Validator::make($skillDeclaration->getAttributes(), [
37
            'skill_id' => [
38 1
                'required',
39 1
                Rule::in($this->skill_ids->toArray()),
40 1
                $uniqueSkillRule,
41
            ],
42
            'applicant_id' => [
43 1
                'required',
44 1
                Rule::in([$this->applicant->id]),
45
            ],
46
            'skill_status_id' => [
47 1
                'required',
48 1
                Rule::in($this->skill_status_ids->toArray()),
49
            ],
50
            'skill_level_id' => [
51 1
                'required',
52 1
                Rule::in($this->skill_level_ids->toArray()),
53
            ],
54 1
            'description' => 'required|string',
55
        ]);
56 1
        return $validator;
57
    }
58
59 1
    public function validate(SkillDeclaration $skillDeclaration)
1 ignored issue
show
introduced by
Method \App\Services\Validation\SkillDeclarationValidator::validate() does not have return type hint nor @return annotation for its return value.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function validate()
Loading history...
60
    {
61 1
        return $this->validator($skillDeclaration)->validate();
62
    }
63
64
65
}
66