function LocalPart::parse
Overrides PartParser::parse
File
-
vendor/
egulias/ email-validator/ src/ Parser/ LocalPart.php, line 35
Class
Namespace
Egulias\EmailValidator\ParserCode
public function parse() : Result {
$this->lexer
->startRecording();
while (!$this->lexer->current
->isA(EmailLexer::S_AT) && !$this->lexer->current
->isA(EmailLexer::S_EMPTY)) {
if ($this->hasDotAtStart()) {
return new InvalidEmail(new DotAtStart(), $this->lexer->current->value);
}
if ($this->lexer->current
->isA(EmailLexer::S_DQUOTE)) {
$dquoteParsingResult = $this->parseDoubleQuote();
//Invalid double quote parsing
if ($dquoteParsingResult->isInvalid()) {
return $dquoteParsingResult;
}
}
if ($this->lexer->current
->isA(EmailLexer::S_OPENPARENTHESIS) || $this->lexer->current
->isA(EmailLexer::S_CLOSEPARENTHESIS)) {
$commentsResult = $this->parseComments();
//Invalid comment parsing
if ($commentsResult->isInvalid()) {
return $commentsResult;
}
}
if ($this->lexer->current
->isA(EmailLexer::S_DOT) && $this->lexer
->isNextToken(EmailLexer::S_DOT)) {
return new InvalidEmail(new ConsecutiveDot(), $this->lexer->current->value);
}
if ($this->lexer->current
->isA(EmailLexer::S_DOT) && $this->lexer
->isNextToken(EmailLexer::S_AT)) {
return new InvalidEmail(new DotAtEnd(), $this->lexer->current->value);
}
$resultEscaping = $this->validateEscaping();
if ($resultEscaping->isInvalid()) {
return $resultEscaping;
}
$resultToken = $this->validateTokens(false);
if ($resultToken->isInvalid()) {
return $resultToken;
}
$resultFWS = $this->parseLocalFWS();
if ($resultFWS->isInvalid()) {
return $resultFWS;
}
$this->lexer
->moveNext();
}
$this->lexer
->stopRecording();
$this->localPart = rtrim($this->lexer
->getAccumulatedValues(), '@');
if (strlen($this->localPart) > LocalTooLong::LOCAL_PART_LENGTH) {
$this->warnings[LocalTooLong::CODE] = new LocalTooLong();
}
return new ValidEmail();
}