Completed
Push — master ( bcf360...98d48e )
by Abdala
03:37
created

Blacklist   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 7
dl 0
loc 22
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 5 3
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CustomerGauge\Password\Rule;
6
7
use CustomerGauge\Password\Exception\InBlacklist;
8
use CustomerGauge\Password\Rule;
9
use function mb_strpos;
10
11
final class Blacklist implements Rule
12
{
13
    /** @var string[] */
14
    private $words;
15
16
    /** @var string */
17
    private $encoding;
18
19
    /**
20
     * @param string[] $words
21
     */
22 1
    public function __construct(array $words, string $encoding = 'utf8')
23
    {
24 1
        $this->words    = $words;
25 1
        $this->encoding = $encoding;
26 1
    }
27
28 1
    public function __invoke(string $password) : void
29
    {
30 1
        foreach ($this->words as $word) {
31 1
            if (mb_strpos($password, $word, 0, $this->encoding) !== false) {
32 1
                throw InBlacklist::contains($word);
33
            }
34
        }
35
    }
36
}
37