EmailValidator::validate()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 10

Duplication

Lines 3
Ratio 30 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 3
loc 10
c 0
b 0
f 0
ccs 0
cts 10
cp 0
rs 9.6111
cc 5
nc 3
nop 2
crap 30
1
<?php declare(strict_types=1);
2
3
namespace indigerd\scenarios\validation\validator;
4
5
class EmailValidator extends AbstractValidator
6
{
7
    protected $pattern = '/^[a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&\'*+\\/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/';
8
9
    public function validate($value, array $context = []): bool
10
    {
11 View Code Duplication
        if ($this->skipOnEmpty and ($value === null || \trim($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...
12
            return true;
13
        }
14
        if (!\is_string($value)) {
15
            return false;
16
        }
17
        return (bool)\preg_match($this->pattern, $value);
18
    }
19
}
20