Completed
Push — master ( a620b9...165629 )
by Paul
01:09
created

Same::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
4
namespace Infinitypaul\Validator\Rules;
5
6
7
use Infinitypaul\Validator\Validator;
8
9
class Same extends Rule
10
{
11
    protected $field;
12
13
    /**
14
     * Same constructor.
15
     *
16
     * @param $field
17
     */
18
    public function __construct($field)
19
    {
20
21
        $this->field = $field;
22
    }
23
24
    /**
25
     * @param $field
26
     * @param $value
27
     * @param $data
28
     *
29
     * @return bool
30
     */
31
    public function passes($field, $value, $data): bool
32
    {
33
        if($value === $data[$this->field]){
34
            return true;
35
        }
36
        return false;
37
    }
38
39
    /**
40
     * @param $field
41
     *
42
     * @return string
43
     */
44
    public function message($field): string
45
    {
46
        return $field.' Doesnt Match With '. Validator::alias($this->field);
47
    }
48
}
49