diff --git a/src/Egulias/EmailValidator/EmailParser.php b/src/Egulias/EmailValidator/EmailParser.php index 347588f..de13f6a 100644 --- a/src/Egulias/EmailValidator/EmailParser.php +++ b/src/Egulias/EmailValidator/EmailParser.php @@ -308,32 +308,18 @@ class EmailParser do { $prev = $this->lexer->getPrevious(); - if ($this->lexer->token['type'] === EmailLexer::S_AT) { - throw new \InvalidArgumentException('ERR_CONSECUTIVEATS'); - } - if ($this->lexer->token['type'] === EmailLexer::S_OPENQBRACKET && $prev['type'] !== EmailLexer::S_AT) { - throw new \InvalidArgumentException('ERR_EXPECTING_ATEXT'); - } if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) { $this->parseComments(); $this->lexer->moveNext(); } $this->checkConsecutiveDots(); - - if ($this->lexer->token['type'] === EmailLexer::S_HYPHEN && $this->lexer->isNextToken(EmailLexer::S_DOT)) { - throw new \InvalidArgumentException('ERR_DOMAINHYPHENEND'); - } + $this->checkDomainPartExceptions(); if ($this->hasBrackets()) { $this->parseDomainLiteral(); } - if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH - && $this->lexer->isNextToken(EmailLexer::GENERIC)) { - throw new \InvalidArgumentException('ERR_EXPECTING_ATEXT'); - } - $this->checkLabelLength($prev); if ($this->isFWS()) { @@ -503,4 +489,22 @@ class EmailParser return true; } + + private function checkDomainPartExceptions() + { + if ($this->lexer->token['type'] === EmailLexer::S_AT) { + throw new \InvalidArgumentException('ERR_CONSECUTIVEATS'); + } + if ($this->lexer->token['type'] === EmailLexer::S_OPENQBRACKET && $prev['type'] !== EmailLexer::S_AT) { + throw new \InvalidArgumentException('ERR_EXPECTING_ATEXT'); + } + if ($this->lexer->token['type'] === EmailLexer::S_HYPHEN && $this->lexer->isNextToken(EmailLexer::S_DOT)) { + throw new \InvalidArgumentException('ERR_DOMAINHYPHENEND'); + } + + if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH + && $this->lexer->isNextToken(EmailLexer::GENERIC)) { + throw new \InvalidArgumentException('ERR_EXPECTING_ATEXT'); + } + } }