PasswordValidator::getValidators()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
ccs 0
cts 3
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Porthou\Password;
5
6
class PasswordValidator
7
{
8
    /** @var Validator[] $validators */
9
    private $validators = [];
10
11
    public function __construct(iterable $validators = [])
12
    {
13
        foreach ($validators as $validator) {
14
            $this->addValidator($validator);
15
        }
16
    }
17
18
    /**
19
     * Adds a validator to the current PasswordValidator instance
20
     *
21
     * @param Validator $validator
22
     */
23
    public function addValidator(Validator $validator): void
24
    {
25
        $this->validators[] = $validator;
26
    }
27
28
    /**
29
     * Gets an array of the currently applied Validators
30
     *
31
     * @return Validator[]
32
     */
33
    public function getValidators(): array
34
    {
35
        return $this->validators;
36
    }
37
38
    /**
39
     * Validates the given password against the current rule set.
40
     *
41
     * @param string $password
42
     * @return bool True if the password is valid
43
     * @throws PasswordException If the password fails a validation attempt.
44
     */
45
    public function validate(string $password): bool
46
    {
47
        foreach ($this->validators as $validator) {
48
            $validator->validate($password);
49
        }
50
51
        return true;
52
    }
53
}
54