HashedBasicEquals::validate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 2
rs 10
1
<?php
2
3
namespace kalanis\kw_rules\Rules\Safe;
4
5
6
use kalanis\kw_rules\Interfaces\IValidate;
7
use kalanis\kw_rules\Exceptions\RuleException;
8
use kalanis\kw_rules\Rules\ARule;
9
10
11
/**
12
 * Class HashedBasicEquals
13
 * @package kalanis\kw_rules\Rules\Safe
14
 * Check if input hash is equal to hash of expected value
15
 */
16
class HashedBasicEquals extends ARule
17
{
18 2
    public function validate(IValidate $entry): void
19
    {
20 2
        if ($this->hash(strval($entry->getValue())) != $this->hash(strval($this->againstValue))) {
21 1
            throw new RuleException($this->errorText);
22
        }
23 1
    }
24
25 2
    protected function hash(string $input): string
26
    {
27 2
        return md5($input);
28
    }
29
}
30