Passed
Pull Request — master (#1)
by
unknown
02:04
created

Email::filter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace TraderInteractive\Filter;
4
5
use TraderInteractive\Exceptions\FilterException;
6
7
/**
8
 * A collection of filters for emails.
9
 */
10
final class Email
11
{
12
    /**
13
     * Filter an email
14
     *
15
     * The return value is the email, as expected by the \TraderInteractive\Filterer class.
16
     *
17
     * @param mixed $value The value to filter.
18
     *
19
     * @return string The passed in $value.
20
     *
21
     * @throws FilterException if the value did not pass validation.
22
     */
23
    public static function filter(string $value) : string
24
    {
25
        return self::validateEmail($value);
26
    }
27
28
    private static function validateEmail(string $value) : string
29
    {
30
        $filteredEmail = filter_var($value, FILTER_VALIDATE_EMAIL);
31
        if ($filteredEmail === false) {
32
            throw new FilterException("Value '{$value}' is not a valid email");
33
        }
34
        
35
        return $filteredEmail;
36
    }
37
}
38