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

NonUniqueEmailType::isValid()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3

Importance

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