PasswordLengthValidator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
eloc 6
dl 0
loc 23
c 0
b 0
f 0
ccs 0
cts 10
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A validate() 0 7 2
A __construct() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Porthou\Password\Validators;
5
6
use Porthou\Password\PasswordException;
7
use Porthou\Password\Validator;
8
9
class PasswordLengthValidator implements Validator
10
{
11
    /** @var int $length */
12
    private $length;
13
14
    /**
15
     * PasswordLengthValidator constructor.
16
     *
17
     * @param int $length The minimum length the password must be
18
     */
19
    public function __construct(int $length = 8)
20
    {
21
        $this->length = $length;
22
    }
23
24
    /** {@inheritdoc} */
25
    public function validate(string $password): bool
26
    {
27
        if (mb_strlen($password) >= $this->length) {
28
            return true;
29
        }
30
31
        throw new PasswordException('Password is too short. It should be at least ' . $this->length . ' characters');
32
    }
33
}
34