Email   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 27
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A filter() 0 13 3
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