Validator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
c 1
b 0
f 0
dl 0
loc 44
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A passwordVerify() 0 3 1
A createHash() 0 3 1
A isValid() 0 3 1
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