HashFunc   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 4
dl 0
loc 38
c 0
b 0
f 0
ccs 4
cts 4
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 3 1
A length() 0 3 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\PKCS5\HashFunc;
6
7
/**
8
 * Base class for hash functions used in password-based cryptography.
9
 */
10
abstract class HashFunc
11
{
12
    /**
13
     * Length of the produced hash in bytes.
14
     *
15
     * @var int
16
     */
17
    protected $_length;
18
19
    /**
20
     * Functor interface.
21
     *
22
     * @param string $data
23
     *
24
     * @return string
25
     */
26 13
    public function __invoke(string $data): string
27
    {
28 13
        return $this->hash($data);
29
    }
30
31
    /**
32
     * Hash function.
33
     *
34
     * @param string $data
35
     *
36
     * @return string Hash result in raw format
37
     */
38
    abstract public function hash(string $data): string;
39
40
    /**
41
     * Get hash length.
42
     *
43
     * @return int
44
     */
45 14
    public function length(): int
46
    {
47 14
        return $this->_length;
48
    }
49
}
50