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

Digit   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 5
dl 0
loc 16
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A __invoke() 0 6 2
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