Email::filter()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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