Passed
Push — task/application-handle-step-s... ( 5f39f9...d6d197 )
by Yonathan
05:39
created

ContainsArrayWithAttributeRule::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 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 ContainsArrayWithAttributeRule implements Rule
9
{
10
11
    protected $attributeName;
12
    protected $attributeValue;
13
14
    /**
15
     * Create a new rule instance.
16
     *
17
     * @param  string $attributeName
18
     * @param  mixed  $attributeValue
19
     * @return void
20
     */
21
    public function __construct($attributeName, $attributeValue)
22
    {
23
        $this->attributeName = $attributeName;
24
        $this->attributeValue = $attributeValue;
25
    }
26
27
    /**
28
     * This check passes if the $value is an array which contains an
29
     * attributeName relation equal to attributeValue.
30
     * @param  mixed $attribute
31
     * @param  mixed $value
32
     * @return boolean
33
     */
34
    public function passes($attribute, $value)
35
    {
36
        return $value[$this->attributeName] == $this->attributeValue;
37
    }
38
39
    public function message()
40
    {
41
        return Lang::get(
42
            'validation.contains_array_with_attribute',
43
            [
44
                'relation' => $this->attributeName,
45
                'attributeValue' => $this->attributeValue
46
            ]
47
        );
48
    }
49
}
50