ApplicantHasRelationRule::__construct()   A
last analyzed

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 2
crap 2
1
<?php
2
3
namespace App\Services\Validation\Rules;
4
5
use Illuminate\Contracts\Validation\Rule;
6
use Illuminate\Support\Facades\Lang;
7
8
class ApplicantHasRelationRule implements Rule
9
{
10
11
    protected $applicant;
12
    protected $relation;
13
14
    /**
15
     * Create a new rule instance.
16
     *
17
     * @param  App\Models\Applicant  $applicant
0 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...
18
     * @param  string  $relation
19
     * @return void
20
     */
21
    public function __construct($applicant, $relation)
22
    {
23
        $this->applicant = $applicant;
24
        $this->relation = $relation;
25
    }
26
27
    /**
28
     * This check passes if the model's relation contains an object whose id=$value
29
     * @param  [type] $attribute [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...
30
     * @param  [type] $value     [description]
31
     * @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...
32
     */
33
    public function passes($attribute, $value)
34
    {
35
        return $this->applicant->getRelationValue($this->relation)
36
            ->pluck('id')->contains($value);
37
    }
38
39
    public function message()
40
    {
41
        return Lang::get('validation.applicant_has_relation');
42
    }
43
}
44