Passed
Push — master ( 91f02d...65071d )
by Melech
21:33 queued 07:21
created

PhpPasswordHasher::confirmPassword()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Valkyrja Framework package.
7
 *
8
 * (c) Melech Mizrachi <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Valkyrja\Auth\Hasher;
15
16
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
17
use Valkyrja\Auth\Hasher\Contract\PasswordHasher as Contract;
18
19
use const PASSWORD_DEFAULT;
20
21
/**
22
 * Class PhpPasswordHasher.
23
 *
24
 * @author Melech Mizrachi
25
 */
26
class PhpPasswordHasher implements Contract
27
{
28
    /**
29
     * Hash a given password.
30
     *
31
     * @param non-empty-string $password The password to hash
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
32
     *
33
     * @return non-empty-string
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
34
     */
35
    #[Override]
36
    public function hashPassword(string $password): string
37
    {
38
        /** @var non-empty-string $hashedPassword */
39
        $hashedPassword = password_hash($password, PASSWORD_DEFAULT);
40
41
        return $hashedPassword;
42
    }
43
44
    /**
45
     * Compare an plain text password with a given hashed password.
46
     *
47
     * @param string $password       The plain text password
48
     * @param string $hashedPassword The hashed password
49
     *
50
     * @return bool
51
     */
52
    #[Override]
53
    public function confirmPassword(string $password, string $hashedPassword): bool
54
    {
55
        return password_verify($password, $hashedPassword);
56
    }
57
}
58