Passed
Pull Request — master (#167)
by
unknown
02:48
created

NonLocalValidation::getWarnings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace Egulias\EmailValidator\Validation;
4
5
use Egulias\EmailValidator\EmailLexer;
6
use Egulias\EmailValidator\Exception\InvalidEmail;
7
use Egulias\EmailValidator\Validation\Error\LocalEmail;
8
9
class NonLocalValidation implements EmailValidation
10
{
11
    /**
12
     * @var InvalidEmail
13
     */
14
    private $error;
15
16 4
    public function isValid($email, EmailLexer $emailLexer)
17
    {
18
        // use the input to check DNS if we cannot extract something similar to a domain
19 4
        $host = $email;
20
21
        // Arguable pattern to extract the domain. Not aiming to validate the domain nor the email
22 4 View Code Duplication
        if (false !== $lastAtPos = strrpos($email, '@')) {
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...
23 4
            $host = substr($email, $lastAtPos + 1);
24 4
        }
25
26 4
        if (false === strpos($host, '.')) {
27 2
            $this->error = new LocalEmail();
28 2
        }
29
30 4
        return $this->error === null;
31
    }
32
33 2
    public function getError()
34
    {
35 2
        return $this->error;
36
    }
37
38
    public function getWarnings()
39
    {
40
        return [];
41
    }
42
}
43