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

Same   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 40
rs 10
c 0
b 0
f 0

3 Methods

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