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

Digit::getMessage()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 35
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 5

Importance

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