Passed
Push — feature/delete_items ( abdbb3...c1e89b )
by Tristan
09:18
created

UniqueApplicantSkillRule::message()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 2
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\Rules;
4
5
use Illuminate\Contracts\Validation\Rule;
6
use Illuminate\Support\Facades\Hash;
7
use Illuminate\Support\Facades\Auth;
8
use Illuminate\Support\Facades\Lang;
9
use App\Models\Applicant;
10
11
class UniqueApplicantSkillRule implements Rule
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class UniqueApplicantSkillRule
Loading history...
12
{
13
14
    protected $applicant;
15
    protected $skill_declaration_id;
16
17
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $applicant should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $skill_declaration_id should have a doc-comment as per coding-style.
Loading history...
18
     * Create a new rule instance.
19
     *
20
     * @param  App\Models\Applicant  $user
0 ignored issues
show
Bug introduced by
The type App\Services\Validation\Rules\App\Models\Applicant was not found. Did you mean App\Models\Applicant? If so, make sure to prefix the type with \.
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 1 spaces after parameter type; 2 found
Loading history...
Coding Style introduced by
Doc comment for parameter $user does not match actual variable name $applicant
Loading history...
21
     * @return void
0 ignored issues
show
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
22
     */
23
    public function __construct(Applicant $applicant, $skill_declaration_id = null)
24
    {
25
        $this->applicant = $applicant;
26
        $this->skill_declaration_id = $skill_declaration_id;
27
    }
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]
0 ignored issues
show
Documentation Bug introduced by
The doc comment [type] at position 0 could not be parsed: Unknown type name '[' at position 0 in [type].
Loading history...
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
33
     * @param  [type] $value     [description]
34
     * @return [type]            [description]
0 ignored issues
show
Documentation Bug introduced by
The doc comment [type] at position 0 could not be parsed: Unknown type name '[' at position 0 in [type].
Loading history...
Coding Style introduced by
Tag cannot be grouped with parameter tags in a doc comment
Loading history...
35
     */
36
    public function passes($attribute, $value)
37
    {
38
        $prev_skills = $this->applicant->skill_declarations->where('skill_id', $value)->pluck('id');
39
40
        return $prev_skills->isEmpty() ||
41
            ($this->skill_declaration_id != null && $prev_skill->contains($this->skill_declaration_id));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $prev_skill does not exist. Did you maybe mean $prev_skills?
Loading history...
42
    }
43
44
    public function message()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function message()
Loading history...
45
    {
46
        return Lang::get('validation.custom.user_skill_unique');
47
    }
48
}
49