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

NonLocalValidation   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 8.82 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 84.62%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 3
loc 34
ccs 11
cts 13
cp 0.8462
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A isValid() 3 16 3
A getError() 0 4 1
A getWarnings() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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