Passed
Pull Request — 3.x (#348)
by
unknown
01:48
created

IDRightPart::validateTokens()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2.0023

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 11
cts 12
cp 0.9167
crap 2.0023
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 6
        $invalidDomainTokens = [
16 6
            EmailLexer::S_DQUOTE => true,
17 6
            EmailLexer::S_SQUOTE => true,
18 6
            EmailLexer::S_BACKTICK => true,
19 6
            EmailLexer::S_SEMICOLON => true,
20 6
            EmailLexer::S_GREATERTHAN => true,
21 6
            EmailLexer::S_LOWERTHAN => true,
22 6
        ];
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
}
30