Completed
Pull Request — master (#143)
by Christian
03:26
created

SpoofCheckValidation   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 66.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 36
ccs 10
cts 15
cp 0.6667
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A isValid() 0 11 2
A getError() 0 4 1
A getWarnings() 0 4 1
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\SpoofEmail;
8
use \Spoofchecker;
9
10
class SpoofCheckValidation implements EmailValidation
11
{
12
    /**
13
     * @var InvalidEmail
14
     */
15
    private $error;
16
    
17 1
    public function __construct()
18
    {
19 1
        if (!class_exists(Spoofchecker::class)) {
20
            throw new \LogicException(sprintf('The %s class requires the Intl extension.', __CLASS__));
21
        }
22 1
    }
23
24 1
    public function isValid($email, EmailLexer $emailLexer)
25
    {
26 1
        $checker = new Spoofchecker();
27 1
        $checker->setChecks(Spoofchecker::SINGLE_SCRIPT);
28
29 1
        if ($checker->isSuspicious($email)) {
30 1
            $this->error = new SpoofEmail();
31 1
        }
32
33 1
        return $this->error === null;
34
    }
35
36
    public function getError()
37
    {
38
        return $this->error;
39
    }
40
41
    public function getWarnings()
42
    {
43
        return [];
44
    }
45
}
46