Passed
Push — master ( 42c0a5...fd8aa5 )
by Adrien
10:46
created

DeliverableEmail   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

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 extends EmailAddress
15
{
16 20
    public function isValid($value)
17
    {
18
        // This regexp should be kep in sync with the original one in Natural
19 20
        if (!preg_match('/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[^@]+\.[^@]+$/u', $value)) {
20 12
            $this->error(self::INVALID_LOCAL_PART);
21
22 12
            return false;
23
        }
24
25 8
        return parent::isValid($value);
26
    }
27
}
28