Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
8 / 8 |
|
87.50% |
7 / 8 |
|
37.50% |
3 / 8 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| |
100.00% |
8 / 8 |
|
87.50% |
7 / 8 |
|
37.50% |
3 / 8 |
|
100.00% |
1 / 1 |
5.20 | |
100.00% |
1 / 1 |
|
| validate | |
100.00% |
8 / 8 |
|
87.50% |
7 / 8 |
|
37.50% |
3 / 8 |
|
100.00% |
1 / 1 |
5.20 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Celemas\Sire\Rule; |
| 6 | |
| 7 | use Celemas\Sire\Contract; |
| 8 | use Celemas\Sire\Validation; |
| 9 | use Override; |
| 10 | |
| 11 | /** @api */ |
| 12 | final class Email implements Contract\Rule |
| 13 | { |
| 14 | public string $message { |
| 15 | get => '{label} must be a valid email address'; |
| 16 | } |
| 17 | |
| 18 | #[Override] |
| 19 | public function validate(Contract\Value $value, string ...$args): Contract\Validation |
| 20 | { |
| 21 | $email = filter_var( |
| 22 | trim((string) $value->value), |
| 23 | \FILTER_VALIDATE_EMAIL, |
| 24 | ); |
| 25 | |
| 26 | if ($email !== false && ($args[0] ?? null) === 'checkdns') { |
| 27 | [, $mailDomain] = explode('@', $email); |
| 28 | |
| 29 | return Validation::from(checkdnsrr($mailDomain, 'MX')); |
| 30 | } |
| 31 | |
| 32 | return Validation::from($email !== false); |
| 33 | } |
| 34 | } |