PasswordManager::verify()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Security\Authentication;
6
7
use Chubbyphp\Security\Authentication\Exception\EmptyPasswordException;
8
9
final class PasswordManager implements PasswordManagerInterface
10
{
11
    /**
12
     * @param string $password
13
     *
14
     * @return string
15
     *
16
     * @throws EmptyPasswordException
17
     */
18 2
    public function hash(string $password): string
19
    {
20 2
        if ('' === $password) {
21 1
            throw EmptyPasswordException::create();
22
        }
23
24 1
        return password_hash($password, PASSWORD_DEFAULT);
25
    }
26
27
    /**
28
     * @param string $password
29
     * @param string $hash
30
     *
31
     * @return bool
32
     */
33 2
    public function verify(string $password, string $hash): bool
34
    {
35 2
        return password_verify($password, $hash);
36
    }
37
}
38