EmailValidator   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 5
c 2
b 0
f 1
dl 0
loc 10
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A validate() 0 8 2
1
<?php declare(strict_types=1);
2
3
namespace Phypes\Validator;
4
5
use Phypes\Error\TypeError;
6
use Phypes\Error\TypeErrorCode;
7
use Phypes\Result\Failure;
8
use Phypes\Result\Result;
9
use Phypes\Result\Success;
10
11
class EmailValidator implements Validator
12
{
13
    public function validate($email): Result
14
    {
15
        if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
16
            return new Success();
17
        }
18
19
        $error = new TypeError(TypeErrorCode::EMAIL_INVALID, 'The provided email is invalid.');
20
        return new Failure($error);
21
    }
22
}