DeliverableEmail   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 5
c 2
b 0
f 0
dl 0
loc 12
ccs 5
cts 5
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 10 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ecodev\Felix\Validator;
6
7
use Laminas\Validator\EmailAddress;
8
9
/**
10
 * Validate an email address according to RFC, and also that it is publicly deliverable (not "root@localhost" or "[email protected]").
11
 *
12
 * This is meant to replace **all** usages of Laminas too permissive `\Laminas\Validator\EmailAddress`
13
 */
14
class DeliverableEmail
15
{
16 22
    public function isValid(string $value): bool
17
    {
18
        // This regexp should be kep in sync with the original one in Natural
19 22
        if (!preg_match('/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[^@ ]+\.[^@]+$/u', $value)) {
20 14
            return false;
21
        }
22
23 8
        $validator = new EmailAddress();
24
25 8
        return $validator->isValid($value);
26
    }
27
}
28