Completed
Pull Request — dev (#515)
by Tristan
15:51 queued 07:35
created

SkillDeclarationValidator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
eloc 27
dl 0
loc 46
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A validate() 0 28 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 validate(SkillDeclaration $skillDeclaration)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function validate()
Loading history...
33
    {
34
        $uniqueSkillRule = new UniqueApplicantSkillRule($this->applicant, $skillDeclaration->id);
35
36
        //This array is reset every time because applicants table can change frequently
37
        $applicant_ids = Applicant::all()->pluck('id');
38
39
        //Validate basic data is filled in
40
        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...
41
            'skill_id' => [
42
                'required',
43
                Rule::in($this->skill_ids->toArray()),
44
                $uniqueSkillRule,
45
            ],
46
            'applicant_id' => [
47
                'required',
48
                Rule::in($applicant_ids->toArray()),
49
            ],
50
            'skill_status_id' => [
51
                'required',
52
                Rule::in($this->skill_status_ids->toArray()),
53
            ],
54
            'skill_level_id' => [
55
                'required',
56
                Rule::in($this->skill_level_ids->toArray()),
57
            ],
58
            'description' => 'string|required',
59
        ])->validate();
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...
60
    }
61
}
62