Completed
Push — dev ( 170d5a...aca493 )
by Tristan
06:11
created

JobApplicationAnswerValidator::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 13
ccs 0
cts 7
cp 0
rs 9.9666
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;
4
5
use App\Models\JobApplication;
6
use App\Models\JobApplicationAnswer;
7
use Illuminate\Support\Facades\Validator;
8
use Illuminate\Validation\Rule;
9
10
class JobApplicationAnswerValidator {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class JobApplicationAnswerValidator
Loading history...
Coding Style introduced by
Opening brace of a class must be on the line after the definition
Loading history...
11
12
    protected $application;
13
    protected $questionIds;
14
15
    public function __construct(JobApplication $application) {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function __construct()
Loading history...
16
        $this->application = $application;
17
        $this->questionIds = $application->job_poster->job_poster_questions->pluck('id')->toArray();
18
    }
19
20
    public function rules() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function rules()
Loading history...
21
        $rules = [
22
            'answer' => 'required|string',
23
            'job_poster_question_id' => [
24
                'required',
25
                Rule::in($this->questionIds),
26
            ],
27
            'job_application_id' => [
28
                'required',
29
                Rule::in([$this->application->id]),
30
            ]
31
        ];
32
        return $rules;
33
    }
34
35
    public function validator(JobApplicationAnswer $answer) {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function validator()
Loading history...
36
37
38
        return Validator::make($answer->toArray(), $this->rules());
39
    }
40
41
    public function validate(JobApplicationAnswer $answer) {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function validate()
Loading history...
42
        return $this->validator($answer)->validate();
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->validator($answer)->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...
43
    }
44
45
    public function isComplete(JobApplicationAnswer $answer) {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function isComplete()
Loading history...
46
        return $this->validator($answer)->passes();
47
    }
48
}
49