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

SpoofCheckValidation::getWarnings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

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
eloc 2
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\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