ApplicantHasRelationRule   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
eloc 8
dl 0
loc 34
ccs 0
cts 9
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A message() 0 3 1
A passes() 0 4 1
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