Completed
Push — feature/application_tracker_va... ( fa2127...f58e89 )
by Tristan
11:57 queued 04:59
created

SkillDeclarationValidator::validator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 28
ccs 0
cts 15
cp 0
rs 9.6666
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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 validator(SkillDeclaration $skillDeclaration) {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function validator()
Loading history...
33
        $uniqueSkillRule = new UniqueApplicantSkillRule($this->applicant, $skillDeclaration->id);
34
35
        //This array is reset every time because applicants table can change frequently
36
        $applicant_ids = Applicant::all()->pluck('id');
37
38
        //Validate basic data is filled in
39
        $validator = 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...
40
            'skill_id' => [
41
                'required',
42
                Rule::in($this->skill_ids->toArray()),
43
                $uniqueSkillRule,
44
            ],
45
            'applicant_id' => [
46
                'required',
47
                Rule::in($applicant_ids->toArray()),
48
            ],
49
            'skill_status_id' => [
50
                'required',
51
                Rule::in($this->skill_status_ids->toArray()),
52
            ],
53
            'skill_level_id' => [
54
                'required',
55
                Rule::in($this->skill_level_ids->toArray()),
56
            ],
57
            'description' => 'string|required',
58
        ]);
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...
59
        return $validator;
60
    }
61
62
    public function validate(SkillDeclaration $skillDeclaration)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function validate()
Loading history...
63
    {
64
        return $this->validator($skillDeclaration)->validate();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->validator($skillDeclaration)->validate() targeting Illuminate\Validation\Validator::validate() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
65
    }
66
67
68
}
69