Failed Conditions
Pull Request — master (#1)
by
unknown
02:02
created

Email   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A filter() 0 12 3
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($value) : string
24
    {
25
        if (!is_string($value)) {
26
            throw new FilterException("Value '" . var_export($value, true) . "' is not a string");
27
        }
28
29
        $filteredEmail = filter_var($value, FILTER_VALIDATE_EMAIL);
30
        if ($filteredEmail === false) {
31
            throw new FilterException("Value '{$value}' is not a valid email");
32
        }
33
34
        return $filteredEmail;
35
    }
36
}
37