Same::passes()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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