Passed
Push — master ( c0ff8f...66dfac )
by Adrien
02:28
created

NonUniqueEmailType   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A isValid() 0 5 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ecodev\Felix\Api\Scalar;
6
7
use Laminas\Validator\EmailAddress;
8
9
/**
10
 * Represent an email address that can be empty string
11
 *
12
 * This support the rare cases where an email is **not** unique in DB. And thus we want the
13
 * field to be non-null and allow empty string to represent absence of value as we usually do
14
 * for string fields.
15
 */
16
final class NonUniqueEmailType extends AbstractStringBasedType
17
{
18
    /**
19
     * Validate a email
20
     *
21
     * @param mixed $value
22
     */
23 14
    protected function isValid($value): bool
24
    {
25 14
        $validator = new EmailAddress();
26
27 14
        return $value === '' || (is_string($value) && $validator->isValid($value));
28
    }
29
}
30