PasswordValidator::validate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 11
ccs 0
cts 8
cp 0
crap 2
rs 10
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/validize project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Daikon\Validize\Validator;
10
11
use Daikon\Interop\Assertion;
12
13
final class PasswordValidator extends Validator
14
{
15
    private const MIN_LEN = 8;
16
    private const MAX_LEN = 60;
17
18
    /** @param mixed $input */
19
    protected function validate($input): string
20
    {
21
        $settings = $this->getSettings();
22
        $min = $settings['min'] ?? self::MIN_LEN;
23
        $max = $settings['max'] ?? self::MAX_LEN;
24
25
        Assertion::string($input, 'Must be a string.');
26
        $password = trim($input);
27
        Assertion::betweenLength($password, $min, $max, "Must be between $min and $max characters.");
28
29
        return $password;
30
    }
31
}
32