Passed
Push — message-id-validator ( 1cb5b2...07464f )
by Eduardo Gulias
02:11
created

IDLeftPart::validateTokens()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 4
cts 5
cp 0.8
rs 9.7333
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.032
1
<?php
2
3
namespace Egulias\EmailValidator\Parser;
4
5
use Egulias\EmailValidator\EmailLexer;
6
use Egulias\EmailValidator\Result\Result;
7
use Egulias\EmailValidator\Result\ValidEmail;
8
use Egulias\EmailValidator\Result\InvalidEmail;
9
use Egulias\EmailValidator\Result\Reason\ExpectingATEXT;
10
11
class IDLeftPart extends DomainPart
12
{
13 3
    protected function validateTokens(bool $hasComments) : Result
14
    {
15
        $invalidDomainTokens = array(
16 3
            EmailLexer::S_DQUOTE => true,
17
            EmailLexer::S_SQUOTE => true,
18
            EmailLexer::S_BACKTICK => true,
19
            EmailLexer::S_SEMICOLON => true,
20
            EmailLexer::S_GREATERTHAN => true,
21
            EmailLexer::S_LOWERTHAN => true,
22
        );
23
    
24 3
        if (isset($invalidDomainTokens[$this->lexer->token['type']])) {
25
            return new InvalidEmail(new ExpectingATEXT('Invalid token in domain: ' . $this->lexer->token['value']), $this->lexer->token['value']);
26
        }
27 3
        return new ValidEmail();
28
    }
29
}