Passed
Push — task/laravel-breadcrumbs ( 3beccb...a96280 )
by Yonathan
10:46 queued 10s
created

UniqueSkillDeclarationRule   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 10
dl 0
loc 37
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A passes() 0 7 3
A message() 0 3 1
1
<?php
2
3
namespace App\Services\Validation\Rules;
4
5
use Illuminate\Contracts\Validation\Rule;
6
use Illuminate\Support\Facades\Lang;
7
use App\Models\Applicant;
8
use App\Models\SkillDeclaration;
9
10
class UniqueSkillDeclarationRule implements Rule
11
{
12
13
    protected $existing_declarations;
1 ignored issue
show
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
14
    protected $skill_declaration_id;
1 ignored issue
show
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
15
16
    /**
2 ignored issues
show
Coding Style Documentation introduced by
Doc comment for parameter "$skill_declaration_id" missing
Loading history...
Coding Style Documentation introduced by
Doc comment for parameter "$existing_declarations" missing
Loading history...
17
     * Create a new rule instance.
18
     *
19
     * @param  App\Models\Applicant  $user
2 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 Documentation 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 $existing_declarations
Loading history...
20
     * @return void
21
     */
22
    public function __construct($existing_declarations, $skill_declaration_id = null)
1 ignored issue
show
Coding Style introduced by
Type hint "App\Models\Applicant" missing for $user
Loading history...
introduced by
Method \App\Services\Validation\Rules\UniqueSkillDeclarationRule::__construct() does not have parameter type hint nor @param annotation for its parameter $existing_declarations.
Loading history...
introduced by
Method \App\Services\Validation\Rules\UniqueSkillDeclarationRule::__construct() does not have parameter type hint nor @param annotation for its parameter $skill_declaration_id.
Loading history...
23
    {
24
        $this->existing_declarations = $existing_declarations;
25
        $this->skill_declaration_id = $skill_declaration_id;
26
    }
27
28
    /**
29
     * This check passes if no there are no previous declarations for this skill,
30
     * or if they are updating a previously existing declaration
31
     * @param  [type] $attribute [description]
2 ignored issues
show
Coding Style introduced by
Parameter comment must start with a capital letter
Loading history...
Coding Style Documentation introduced by
Parameter comment must end with a full stop
Loading history...
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...
32
     * @param  [type] $value     [description]
2 ignored issues
show
Coding Style introduced by
Parameter comment must start with a capital letter
Loading history...
Coding Style Documentation introduced by
Parameter comment must end with a full stop
Loading history...
33
     * @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...
34
     */
35
    public function passes($attribute, $value)
3 ignored issues
show
Coding Style introduced by
Type hint "[type]" missing for $attribute
Loading history...
Coding Style introduced by
Type hint "[type]" missing for $value
Loading history...
introduced by
Method \App\Services\Validation\Rules\UniqueSkillDeclarationRule::passes() does not have parameter type hint nor @param annotation for its parameter $attribute.
Loading history...
introduced by
Method \App\Services\Validation\Rules\UniqueSkillDeclarationRule::passes() does not have parameter type hint nor @param annotation for its parameter $value.
Loading history...
introduced by
Method \App\Services\Validation\Rules\UniqueSkillDeclarationRule::passes() does not have return type hint nor @return annotation for its return value.
Loading history...
36
    {
37
        $prev_declarations_of_skill = $this->existing_declarations->where('skill_id', $value);
38
39
        return $prev_declarations_of_skill->isEmpty() ||
40
            ($this->skill_declaration_id != null
41
                && $prev_declarations_of_skill->pluck('id')->contains($this->skill_declaration_id));
42
    }
43
44
    public function message()
2 ignored issues
show
Coding Style Documentation introduced by
Missing doc comment for function message()
Loading history...
introduced by
Method \App\Services\Validation\Rules\UniqueSkillDeclarationRule::message() does not have return type hint nor @return annotation for its return value.
Loading history...
45
    {
46
        return Lang::get('validation.user_skill_unique');
47
    }
48
}
49