Passed
Pull Request — 3.x (#323)
by Eduardo Gulias
09:09 queued 07:19
created

IDRightPart::validateTokens()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 15
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 9.9332
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 IDRightPart extends DomainPart
12
{
13 6
    protected function validateTokens(bool $hasComments) : Result
14
    {
15
        $invalidDomainTokens = [
16
            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 6
        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 6
        return new ValidEmail();
28
    }
29
}