Passed
Push — 3.x ( bcfcb8...c4d50e )
by Eduardo Gulias
06:26 queued 13s
created

EmailValidator   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 60
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A isValid() 0 8 1
A hasWarnings() 0 4 1
A getWarnings() 0 4 1
A getError() 0 4 1
1
<?php
2
3
namespace Egulias\EmailValidator;
4
5
use Egulias\EmailValidator\Result\InvalidEmail;
6
use Egulias\EmailValidator\Validation\EmailValidation;
7
8
class EmailValidator
9
{
10
    /**
11
     * @var EmailLexer
12
     */
13
    private $lexer;
14
15
    /**
16
     * @var Warning\Warning[]
17
     */
18
    private $warnings = [];
19
20
    /**
21
     * @var ?InvalidEmail
22
     */
23
    private $error;
24
25 3
    public function __construct()
26
    {
27 3
        $this->lexer = new EmailLexer();
28 3
    }
29
30
    /**
31
     * @param string          $email
32
     * @param EmailValidation $emailValidation
33
     * @return bool
34
     */
35 3
    public function isValid(string $email, EmailValidation $emailValidation)
36
    {
37 3
        $isValid = $emailValidation->isValid($email, $this->lexer);
38 3
        $this->warnings = $emailValidation->getWarnings();
39 3
        $this->error = $emailValidation->getError();
40
41 3
        return $isValid;
42
    }
43
44
    /**
45
     * @return boolean
46
     */
47 1
    public function hasWarnings()
48
    {
49 1
        return !empty($this->warnings);
50
    }
51
52
    /**
53
     * @return array
54
     */
55 1
    public function getWarnings()
56
    {
57 1
        return $this->warnings;
58
    }
59
60
    /**
61
     * @return InvalidEmail|null
62
     */
63 1
    public function getError()
64
    {
65 1
        return $this->error;
66
    }
67
}
68