DeliverableEmail::isValid()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 4
c 2
b 0
f 0
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 1
crap 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