Same::compare()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 10
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