Same   A
last analyzed

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 4 1
A passes() 0 8 2
A message() 0 4 1
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