Completed
Push — master ( 1eba06...77bc5a )
by Magnar Ovedal
08:14 queued 05:26
created

SymbolRule::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 2
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\Constraint\CountConstraint;
8
use Stadly\PasswordPolice\Policy;
9
10
final class SymbolRule extends CharacterClassRule
11
{
12
    /**
13
     * {@inheritDoc}
14
     */
15 5
    protected function getMessage(CountConstraint $constraint, int $count): string
16
    {
17 5
        $translator = Policy::getTranslator();
18
19 5
        if ($constraint->getMax() === null) {
20 1
            return $translator->trans(
21
                'There must be at least one symbol (%characters%).|'.
22 1
                'There must be at least %count% symbols (%characters%).',
23
                [
24 1
                    '%count%' => $constraint->getMin(),
25 1
                    '%characters%' => $this->characters,
26
                ]
27
            );
28
        }
29
30 4
        if ($constraint->getMax() === 0) {
31 1
            return $translator->trans(
32 1
                'There must be no symbols (%characters%).',
33 1
                ['%characters%' => $this->characters]
34
            );
35
        }
36
37 3
        if ($constraint->getMin() === 0) {
38 1
            return $translator->trans(
39
                'There must be at most one symbol (%characters%).|'.
40 1
                'There must be at most %count% symbols (%characters%).',
41
                [
42 1
                    '%count%' => $constraint->getMax(),
43 1
                    '%characters%' => $this->characters,
44
                ]
45
            );
46
        }
47
48 2
        if ($constraint->getMin() === $constraint->getMax()) {
49 1
            return $translator->trans(
50
                'There must be exactly one symbol (%characters%).|'.
51 1
                'There must be exactly %count% symbols (%characters%).',
52
                [
53 1
                    '%count%' => $constraint->getMin(),
54 1
                    '%characters%' => $this->characters,
55
                ]
56
            );
57
        }
58
59 1
        return $translator->trans(
60 1
            'There must be between %min% and %max% symbols (%characters%).',
61
            [
62 1
                '%min%' => $constraint->getMin(),
63 1
                '%max%' => $constraint->getMax(),
64 1
                '%characters%' => $this->characters,
65
            ]
66
        );
67
    }
68
}
69