ContainsObjectWithRelationRule   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 6
dl 0
loc 34
rs 10
c 0
b 0
f 0

3 Methods

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