Passed
Push — master ( 9e7e6b...999440 )
by Dedipyaman
01:53
created

EmailValidator::validate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 0
loc 10
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Phypes\Validator;
5
6
use Phypes\Error\TypeError\TypeError;
7
use Phypes\Error\TypeError\TypeErrorCode;
8
use Phypes\Result;
9
10
class EmailValidator extends AbstractValidator
11
{
12
    public function validate($email, $options = []): Result
13
    {
14
        $this->validated = true;
0 ignored issues
show
Bug Best Practice introduced by
The property validated does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
15
16
        if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
17
            return $this->success();
18
        }
19
20
        $error = new TypeError(TypeErrorCode::EMAIL_INVALID, 'The provided email is invalid.');
21
        return $this->failure($error);
22
    }
23
24
}