Passed
Push — master ( 028295...075f5a )
by Magnar Ovedal
03:02
created

Symbol::getMessage()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 50
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 26
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 28
nc 5
nop 0
dl 0
loc 50
ccs 26
cts 26
cp 1
crap 5
rs 9.1608
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stadly\PasswordPolice\Rule;
6
7
use Stadly\PasswordPolice\Policy;
8
9
final class Symbol extends CharacterClass
10
{
11
    /**
12
     * {@inheritDoc}
13
     */
14 5
    public function getMessage(): string
15
    {
16 5
        $translator = Policy::getTranslator();
17
18 5
        if ($this->max === null) {
19 1
            return $translator->trans(
20
                'There must be at least one symbol (%characters%).|'.
21 1
                'There must be at least %count% symbols (%characters%).',
22
                [
23 1
                    '%count%' => $this->min,
24 1
                    '%characters%' => $this->characters,
25
                ]
26
            );
27
        }
28
29 4
        if ($this->max === 0) {
30 1
            return $translator->trans(
31 1
                'There must be no symbols (%characters%).',
32 1
                ['%characters%' => $this->characters]
33
            );
34
        }
35
36 3
        if ($this->min === 0) {
37 1
            return $translator->trans(
38
                'There must be at most one symbol (%characters%).|'.
39 1
                'There must be at most %count% symbols (%characters%).',
40
                [
41 1
                    '%count%' => $this->max,
42 1
                    '%characters%' => $this->characters,
43
                ]
44
            );
45
        }
46
47 2
        if ($this->min === $this->max) {
48 1
            return $translator->trans(
49
                'There must be exactly one symbol (%characters%).|'.
50 1
                'There must be exactly %count% symbols (%characters%).',
51
                [
52 1
                    '%count%' => $this->min,
53 1
                    '%characters%' => $this->characters,
54
                ]
55
            );
56
        }
57
58 1
        return $translator->trans(
59 1
            'There must be between %min% and %max% symbols (%characters%).',
60
            [
61 1
                '%min%' => $this->min,
62 1
                '%max%' => $this->max,
63 1
                '%characters%' => $this->characters,
64
            ]
65
        );
66
    }
67
}
68