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

Blacklist::__invoke()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3

Importance

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