| Total Complexity | 5 |
| Total Lines | 33 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 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 | self::validateString($value); |
||
| 26 | return self::validateEmail($value); |
||
| 27 | } |
||
| 28 | |||
| 29 | private static function validateEmail(string $value) : string |
||
| 30 | { |
||
| 31 | $filteredEmail = filter_var($value, FILTER_VALIDATE_EMAIL); |
||
| 32 | if ($filteredEmail === false) { |
||
| 33 | throw new FilterException("Value '{$value}' is not a valid email"); |
||
| 34 | } |
||
| 35 | |||
| 36 | return $filteredEmail; |
||
| 37 | } |
||
| 38 | |||
| 39 | private static function validateString($value) |
||
| 43 | } |
||
| 44 | } |
||
| 45 | } |
||
| 46 |