PasswordManager   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 29
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hash() 0 8 2
A verify() 0 4 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