Same   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 34
ccs 8
cts 8
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A compare() 0 9 2
A sameAs() 0 5 1
1
<?php
2
3
namespace Lavibi\Popoya;
4
5
class Same extends AbstractCompareValidator
6
{
7
    const E_NOT_SAME = 'not_same';
8
9
    protected $messages = [
10
        self::E_NOT_SAME => 'The given value is not same with compared value.'
11
    ];
12
13
    /**
14
     * Set compared value
15
     *
16
     * @param $value
17
     *
18
     * @return $this
19
     */
20 8
    public function sameAs($value)
21
    {
22 8
        $this->options['compared_value'] = $value;
23
24 8
        return $this;
25
    }
26
27
    /**
28
     * @inheritdoc
29
     */
30 6
    protected function compare()
31
    {
32 6
        $result = $this->value === $this->options['compared_value'];
33
34 6
        if (!$result) {
35 3
            $this->setError(self::E_NOT_SAME);
36
        }
37
38 6
        return $result;
39
    }
40
}
41