Completed
Push — master ( 52970f...c6d773 )
by Tristan
24:57 queued 10:40
created

WorkSamplesValidator::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
namespace App\Services\Validation;
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
use Illuminate\Support\Facades\Validator;
4
use Illuminate\Validation\Rule;
5
use App\Models\Applicant;
6
use App\Services\Validation\Rules\UniqueApplicantSkillRule;
7
class WorkSamplesValidator
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class WorkSamplesValidator
Loading history...
8
{
9
    
10
    protected $applicant;
11
    protected $file_type_id;
12
    
13
    public function __construct(Applicant $applicant)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
14
    {
15
        $this->applicant = $applicant;
16
        $this->file_type_id = FileType::all()->pluck('id');
17
    
18
    }
19
    public function validate(WorkSamplesValidatorValidator $workSamplesValidator)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function validate()
Loading history...
20
    {
21
        $uniqueSkillRule = new UniqueApplicantSkillRule($this->applicant, $workSamplesValidator->id);
0 ignored issues
show
Unused Code introduced by
The assignment to $uniqueSkillRule is dead and can be removed.
Loading history...
22
        //This array is reset every time because applicants table can change frequently
23
        $applicant_ids = Applicant::all()->pluck('id');
24
        //Validate basic data is filled in
25
        Validator::make($workSamplesValidator->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...
26
            'applicant_id' => [
27
            'required',
28
               Rule::in($applicant_ids->toArray()),
29
        ],  
30
            'file_type_id' => [
31
            'required',
32
               Rule::in($this->file_type_id->toArray()),
33
        ]           
34
       
35
        ])->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...
36
    }
37
     
38
}