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

CourseValidator::validate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 17
ccs 0
cts 9
cp 0
rs 9.9332
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\Course;
6
use App\Models\Lookup\CourseStatus;
7
use App\Models\Applicant;
8
use App\Services\Validation\Rules\UniqueApplicantSkillRule;
9
class CourseValidator
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class CourseValidator
Loading history...
10
{ 
0 ignored issues
show
Coding Style introduced by
Opening class brace must be on a line by itself
Loading history...
11
    
12
    protected $applicant;
13
    protected $course_status_id;
14
    
15
    public function __construct(Applicant $applicant)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
16
    {
17
        $this->applicant = $applicant;
18
        $this->course_status_ids = CourseStatus::all()->pluck('id');
0 ignored issues
show
Bug Best Practice introduced by
The property course_status_ids does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
19
    }
20
    public function validate(CourseValidator $courseValidator)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function validate()
Loading history...
21
    {
22
        $uniqueSkillRule = new UniqueApplicantSkillRule($this->applicant, $courseValidator->id);
0 ignored issues
show
Unused Code introduced by
The assignment to $uniqueSkillRule is dead and can be removed.
Loading history...
Bug Best Practice introduced by
The property id does not exist on App\Services\Validation\CourseValidator. Did you maybe forget to declare it?
Loading history...
23
        //This array is reset every time because applicants table can change frequently
24
        $applicant_ids = Applicant::all()->pluck('id');
25
        //Validate basic data is filled in
26
        Validator::make($courseValidator->getAttributes(), [ 
0 ignored issues
show
Bug introduced by
The method getAttributes() does not exist on App\Services\Validation\CourseValidator. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
        Validator::make($courseValidator->/** @scrutinizer ignore-call */ getAttributes(), [ 

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
27
            'applicant_id' => [
28
             'required',
29
                Rule::in($applicant_ids->toArray()),
30
       ],
31
             'course_status_id' => [
32
             'required',
33
                Rule::in($this->course_status_ids->toArray()),    
34
     ]
35
         
36
        ])->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...
37
    }
38
    
39
}