Passed
Push — master ( 4e0528...b0f622 )
by Magnar Ovedal
02:36
created

Digit   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 42
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getMessage() 0 35 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stadly\PasswordPolice\Rule;
6
7
use Symfony\Component\Translation\Translator;
8
9
final class Digit extends CharacterClass
10
{
11 7
    public function __construct(int $min, ?int $max = null)
12
    {
13 7
        parent::__construct('0123456789', $min, $max);
14 4
    }
15
16 5
    public function getMessage(Translator $translator): string
17
    {
18 5
        if ($this->getMax() === null) {
19 1
            return $translator->transChoice(
20
                'There must be at least one digit.|'.
21 1
                'There must be at least %count% digits.',
22 1
                $this->getMin()
23
            );
24
        }
25
26 4
        if ($this->getMax() === 0) {
27 1
            return $translator->trans(
28 1
                'There must be no digits.'
29
            );
30
        }
31
32 3
        if ($this->getMin() === 0) {
33 1
            return $translator->transChoice(
34
                'There must be at most one digit.|'.
35 1
                'There must be at most %count% digits.',
36 1
                $this->getMax()
37
            );
38
        }
39
40 2
        if ($this->getMin() === $this->getMax()) {
41 1
            return $translator->transChoice(
42
                'There must be exactly one digit.|'.
43 1
                'There must be exactly %count% digits.',
44 1
                $this->getMin()
45
            );
46
        }
47
48 1
        return $translator->trans(
49 1
            'There must be between %min% and %max% digits.',
50 1
            ['%min%' => $this->getMin(), '%max%' => $this->getMax()]
51
        );
52
    }
53
}
54