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
|
|
|
|