PasswordDomainValidator::validate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
c 0
b 0
f 0
ccs 0
cts 6
cp 0
rs 10
cc 2
nc 2
nop 1
crap 6
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