Completed
Pull Request — master (#75)
by
unknown
01:26
created

Email::filter()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 3
Ratio 23.08 %

Importance

Changes 0
Metric Value
dl 3
loc 13
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 1
1
<?php
2
3
namespace TraderInteractive\Filter;
4
5
/**
6
 * A collection of filters for emails.
7
 */
8
final class Email
9
{
10
    /**
11
     * Filter an email
12
     *
13
     * The return value is the email, as expected by the \TraderInteractive\Filterer class.
14
     *
15
     * @param mixed $value The value to filter.
16
     *
17
     * @return string The passed in $value.
18
     *
19
     * @throws Exception if the value did not pass validation.
20
     */
21
    public static function filter($value) : string
22
    {
23 View Code Duplication
        if (!is_string($value)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
            throw new Exception("Value '" . var_export($value, true) . "' is not a string");
25
        }
26
27
        $filteredEmail = filter_var($value, FILTER_VALIDATE_EMAIL);
28
        if ($filteredEmail === false) {
29
            throw new Exception("Value '{$value}' is not a valid email");
30
        }
31
32
        return $filteredEmail;
33
    }
34
}
35