Total Complexity | 6 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
10 | class AtomValidator |
||
11 | { |
||
12 | // Character sets for unquoted local part |
||
13 | private const ALLOWED_CHARS = '!#$%&\'*+-/=?^_`{|}~.'; |
||
14 | |||
15 | /** |
||
16 | * Validates a dot-atom format local part |
||
17 | * |
||
18 | * @param string $localPart The unquoted local part to validate |
||
19 | * @return bool True if the unquoted local part is valid |
||
20 | */ |
||
21 | public function validate(string $localPart): bool |
||
22 | { |
||
23 | // Empty local part is invalid |
||
24 | if ($localPart === '') { |
||
25 | return false; |
||
26 | } |
||
27 | |||
28 | // Split into atoms |
||
29 | $atoms = explode('.', $localPart); |
||
30 | |||
31 | // Check each atom |
||
32 | foreach ($atoms as $atom) { |
||
33 | if (!$this->validateAtom($atom)) { |
||
34 | return false; |
||
35 | } |
||
36 | } |
||
37 | |||
38 | return true; |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Validates a single atom |
||
43 | * |
||
44 | * @param string $atom The atom to validate |
||
45 | * @return bool True if the atom is valid |
||
46 | */ |
||
47 | private function validateAtom(string $atom): bool |
||
55 | } |
||
56 | } |