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

DeliverableEmail::isValid()   A

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