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

Digit::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace CustomerGauge\Password\Rule;
6
7
use CustomerGauge\Password\Exception\InvalidCharacterType;
8
use CustomerGauge\Password\Rule;
9
use function count;
10
use function preg_match;
11
12
final class Digit implements Rule
13
{
14
    /** @var int */
15
    private $count;
16
17 2
    public function __construct(int $count = 1)
18
    {
19 2
        $this->count = $count;
20 2
    }
21
22 2
    public function __invoke(string $password) : void
23
    {
24 2
        preg_match('/[0-9]/', $password, $matches);
25
26 2
        if (count($matches) < $this->count) {
27 2
            throw InvalidCharacterType::requires('digit', $this->count, count($matches));
28
        }
29
    }
30
}
31