Total Complexity | 5 |
Total Lines | 36 |
Duplicated Lines | 0 % |
Coverage | 80% |
Changes | 0 |
1 | <?php |
||
11 | class UniqueApplicantSkillRule implements Rule |
||
12 | { |
||
13 | |||
14 | protected $applicant; |
||
1 ignored issue
–
show
|
|||
15 | protected $skill_declaration_id; |
||
1 ignored issue
–
show
|
|||
16 | |||
17 | /** |
||
2 ignored issues
–
show
|
|||
18 | * Create a new rule instance. |
||
19 | * |
||
20 | * @param App\Models\Applicant $user |
||
2 ignored issues
–
show
|
|||
21 | * @return void |
||
22 | */ |
||
23 | 1 | public function __construct(Applicant $applicant, $skill_declaration_id = null) |
|
24 | { |
||
25 | 1 | $this->applicant = $applicant; |
|
26 | 1 | $this->skill_declaration_id = $skill_declaration_id; |
|
27 | 1 | } |
|
28 | |||
29 | /** |
||
30 | * This check passes if this applicant has no previous declaration for this skill, |
||
31 | * or if they are updating a previously existing declaration |
||
32 | * @param [type] $attribute [description] |
||
2 ignored issues
–
show
|
|||
33 | * @param [type] $value [description] |
||
2 ignored issues
–
show
|
|||
34 | * @return [type] [description] |
||
35 | */ |
||
36 | 1 | public function passes($attribute, $value) |
|
2 ignored issues
–
show
|
|||
37 | { |
||
38 | 1 | $prev_skills = $this->applicant->skill_declarations->where('skill_id', $value)->pluck('id'); |
|
39 | |||
40 | 1 | return $prev_skills->isEmpty() || |
|
41 | 1 | ($this->skill_declaration_id != null && $prev_skills->contains($this->skill_declaration_id)); |
|
42 | } |
||
43 | |||
44 | public function message() |
||
47 | } |
||
48 | } |
||
49 |