Code Coverage
 
Lines
Branches
Paths
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
87.50% covered (warning)
87.50%
7 / 8
37.50% covered (danger)
37.50%
3 / 8
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
Email
100.00% covered (success)
100.00%
8 / 8
87.50% covered (warning)
87.50%
7 / 8
37.50% covered (danger)
37.50%
3 / 8
100.00% covered (success)
100.00%
1 / 1
5.20
100.00% covered (success)
100.00%
1 / 1
 validate
100.00% covered (success)
100.00%
8 / 8
87.50% covered (warning)
87.50%
7 / 8
37.50% covered (danger)
37.50%
3 / 8
100.00% covered (success)
100.00%
1 / 1
5.20
1<?php
2
3declare(strict_types=1);
4
5namespace Celemas\Sire\Rule;
6
7use Celemas\Sire\Contract;
8use Celemas\Sire\Validation;
9use Override;
10
11/** @api */
12final 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}

Branches

Below are the source code lines that represent each code branch as identified by Xdebug. Please note a branch is not necessarily coterminous with a line, a line may contain multiple branches and therefore show up more than once. Please also be aware that some branches may be implicit rather than explicit, e.g. an if statement always has an else as part of its logical flow even if you didn't write one.

Email->$message::get
15        get => '{label} must be a valid email address';
Email->validate
19    public function validate(Contract\Value $value, string ...$args): Contract\Validation
20    {
21        $email = filter_var(
22            trim((string) $value->value),
22            trim((string) $value->value),
22            trim((string) $value->value),
22            trim((string) $value->value),
23            \FILTER_VALIDATE_EMAIL,
24        );
25
26        if ($email !== false && ($args[0] ?? null) === 'checkdns') {
26        if ($email !== false && ($args[0] ?? null) === 'checkdns') {
26        if ($email !== false && ($args[0] ?? null) === 'checkdns') {
27            [, $mailDomain] = explode('@', $email);
28
29            return Validation::from(checkdnsrr($mailDomain, 'MX'));
32        return Validation::from($email !== false);
33    }