Validator::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Tleckie\Password;
4
5
/**
6
 * Class Validator
7
 *
8
 * @package Tleckie\Password
9
 * @author  Teodoro Leckie Westberg <[email protected]>
10
 */
11
class Validator implements ValidatorInterface
12
{
13
    /** @var RequirementsInterface */
14
    protected RequirementsInterface $requirements;
15
16
    /** @var HashInterface */
17
    protected HashInterface $hash;
18
19
    /**
20
     * Validator constructor.
21
     *
22
     * @param RequirementsInterface|null $requirements
23
     * @param HashInterface|null         $hash
24
     */
25
    public function __construct(
26
        RequirementsInterface $requirements = null,
27
        HashInterface $hash = null
28
    ) {
29
        $this->requirements = $requirements ?? new Requirements();
30
        $this->hash = $hash ?? new Hash();
31
    }
32
33
    /**
34
     * @inheritdoc
35
     */
36
    public function isValid(string $password): bool
37
    {
38
        return $this->requirements->isValid($password);
39
    }
40
41
    /**
42
     * @inheritdoc
43
     */
44
    public function createHash(string $password): string
45
    {
46
        return $this->hash->createHash($password);
47
    }
48
49
    /**
50
     * @inheritdoc
51
     */
52
    public function passwordVerify(string $password, string $hash): bool
53
    {
54
        return $this->hash->passwordVerify($password, $hash);
55
    }
56
}
57