PasswordDomainValidator   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
eloc 6
dl 0
loc 22
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 PasswordDomainValidator implements Validator
10
{
11
    /** @var string $domain */
12
    private $domain;
13
14
    /**
15
     * PasswordDomainValidator constructor.
16
     * @param string $domain The domain to check that the password isn't
17
     */
18
    public function __construct(string $domain)
19
    {
20
        $this->domain = $domain;
21
    }
22
23
    /** {@inheritdoc} */
24
    public function validate(string $password): bool
25
    {
26
        if (mb_strpos($this->domain, $password) === false) {
27
            return true;
28
        }
29
30
        throw new PasswordException('Password is must not contain the current domain name.');
31
    }
32
}
33