ContainsObjectWithRelationRule::message()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 ContainsObjectWithRelationRule implements Rule
9
{
10
11
    protected $validator;
12
13
    /**
14
     * Create a new rule instance.
15
     *
16
     * @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...
17
     * @param  string  $relation
18
     * @return void
19
     */
20
    public function __construct($validator)
21
    {
22
        $this->validator = $validator;
23
    }
24
25
    /**
26
     * This check passes if the $value is a collection which contains an object
27
     *  with a relationName relation equal to relationValue
28
     * @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...
29
     * @param  [type] $value     [description]
30
     * @return boolean            [description]
31
     */
32
    public function passes($attribute, $value)
33
    {
34
        return $value->contains(function ($object) {
35
            $object->getRelationValue($this->relationName)->is($this->relationValue);
36
        });
37
    }
38
39
    public function message()
40
    {
41
        return Lang::get('validation.contains_object_with_relation', ['relation' => $this->relationName]);
42
    }
43
}
44