mirror of
https://github.com/egulias/EmailValidator.git
synced 2026-09-04 22:50:45 +00:00
polishin
This commit is contained in:
@@ -145,7 +145,7 @@ class DomainPart extends Parser
|
||||
}
|
||||
|
||||
$dotsResult = $this->checkConsecutiveDots();
|
||||
if ($dotsResult) {
|
||||
if ($dotsResult->isInvalid()) {
|
||||
return $dotsResult;
|
||||
}
|
||||
$exceptionsResult = $this->checkDomainPartExceptions($prev);
|
||||
@@ -163,11 +163,9 @@ class DomainPart extends Parser
|
||||
|
||||
$this->checkLabelLength($prev);
|
||||
|
||||
if ($this->isFWS()) {
|
||||
$FwsResult = $this->parseFWS();
|
||||
if($FwsResult->isInvalid()) {
|
||||
return $FwsResult;
|
||||
}
|
||||
$FwsResult = $this->parseFWS();
|
||||
if($FwsResult->isInvalid()) {
|
||||
return $FwsResult;
|
||||
}
|
||||
|
||||
$domain .= $this->lexer->token['value'];
|
||||
@@ -260,4 +258,4 @@ class DomainPart extends Parser
|
||||
$this->warnings[TLD::CODE] = new TLD();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,17 +5,12 @@ namespace Egulias\EmailValidator\Parser;
|
||||
use Egulias\EmailValidator\EmailLexer;
|
||||
use Egulias\EmailValidator\Exception\CRLFAtTheEnd;
|
||||
use Egulias\EmailValidator\Exception\CRLFX2;
|
||||
use Egulias\EmailValidator\Exception\ExpectingQPair;
|
||||
use Egulias\EmailValidator\Exception\ExpectingATEXT;
|
||||
use Egulias\EmailValidator\Exception\UnclosedComment;
|
||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
||||
use Egulias\EmailValidator\Result\Reason\ConsecutiveAt;
|
||||
use Egulias\EmailValidator\Result\Reason\ConsecutiveDot;
|
||||
use Egulias\EmailValidator\Result\Reason\ExpectingATEXT as ReasonExpectingATEXT;
|
||||
use Egulias\EmailValidator\Result\Result;
|
||||
use Egulias\EmailValidator\Result\ValidEmail;
|
||||
use Egulias\EmailValidator\Warning\CFWSNearAt;
|
||||
use Egulias\EmailValidator\Warning\Comment;
|
||||
use Egulias\EmailValidator\Warning\QuotedPart;
|
||||
|
||||
abstract class Parser
|
||||
@@ -30,11 +25,6 @@ abstract class Parser
|
||||
*/
|
||||
protected $lexer;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $openedParenthesis = 0;
|
||||
|
||||
public function __construct(EmailLexer $lexer)
|
||||
{
|
||||
$this->lexer = $lexer;
|
||||
@@ -53,93 +43,21 @@ abstract class Parser
|
||||
*/
|
||||
abstract public function parse($str);
|
||||
|
||||
/** @return int */
|
||||
public function getOpenedParenthesis()
|
||||
{
|
||||
return $this->openedParenthesis;
|
||||
}
|
||||
|
||||
/**
|
||||
* validateQuotedPair
|
||||
*/
|
||||
protected function validateQuotedPair()
|
||||
{
|
||||
if (!($this->lexer->token['type'] === EmailLexer::INVALID
|
||||
|| $this->lexer->token['type'] === EmailLexer::C_DEL)) {
|
||||
throw new ExpectingQPair();
|
||||
}
|
||||
|
||||
$this->warnings[QuotedPart::CODE] =
|
||||
new QuotedPart($this->lexer->getPrevious()['type'], $this->lexer->token['type']);
|
||||
}
|
||||
|
||||
protected function parseComments()
|
||||
{
|
||||
$this->openedParenthesis = 1;
|
||||
$this->isUnclosedComment();
|
||||
$this->warnings[Comment::CODE] = new Comment();
|
||||
while (!$this->lexer->isNextToken(EmailLexer::S_CLOSEPARENTHESIS)) {
|
||||
if ($this->lexer->isNextToken(EmailLexer::S_OPENPARENTHESIS)) {
|
||||
$this->openedParenthesis++;
|
||||
}
|
||||
$this->warnEscaping();
|
||||
$this->lexer->moveNext();
|
||||
}
|
||||
|
||||
$this->lexer->moveNext();
|
||||
if ($this->lexer->isNextTokenAny(array(EmailLexer::GENERIC, EmailLexer::S_EMPTY))) {
|
||||
throw new ExpectingATEXT();
|
||||
}
|
||||
|
||||
if ($this->lexer->isNextToken(EmailLexer::S_AT)) {
|
||||
$this->warnings[CFWSNearAt::CODE] = new CFWSNearAt();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function isUnclosedComment()
|
||||
{
|
||||
try {
|
||||
$this->lexer->find(EmailLexer::S_CLOSEPARENTHESIS);
|
||||
return true;
|
||||
} catch (\RuntimeException $e) {
|
||||
throw new UnclosedComment();
|
||||
}
|
||||
}
|
||||
|
||||
protected function parseFWS()
|
||||
protected function parseFWS() : Result
|
||||
{
|
||||
$foldingWS = new FoldingWhiteSpace($this->lexer);
|
||||
$resultFWS = $foldingWS->parse('remove');
|
||||
//if ($resultFWS->isValid()) {
|
||||
$this->warnings = array_merge($this->warnings, $foldingWS->getWarnings());
|
||||
//}
|
||||
$this->warnings = array_merge($this->warnings, $foldingWS->getWarnings());
|
||||
return $resultFWS;
|
||||
}
|
||||
|
||||
protected function checkConsecutiveDots()
|
||||
protected function checkConsecutiveDots() : Result
|
||||
{
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
|
||||
return new InvalidEmail(new ConsecutiveDot(), $this->lexer->token['value']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function isFWS()
|
||||
{
|
||||
if ($this->escaped()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->lexer->token['type'] === EmailLexer::S_SP ||
|
||||
$this->lexer->token['type'] === EmailLexer::S_HTAB ||
|
||||
$this->lexer->token['type'] === EmailLexer::S_CR ||
|
||||
$this->lexer->token['type'] === EmailLexer::S_LF ||
|
||||
$this->lexer->token['type'] === EmailLexer::CRLF;
|
||||
return new ValidEmail();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -199,19 +117,4 @@ abstract class Parser
|
||||
return new ValidEmail();
|
||||
|
||||
}
|
||||
|
||||
protected function checkCRLFInFWS()
|
||||
{
|
||||
if ($this->lexer->token['type'] !== EmailLexer::CRLF) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB))) {
|
||||
throw new CRLFX2();
|
||||
}
|
||||
|
||||
if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB))) {
|
||||
throw new CRLFAtTheEnd();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ namespace Egulias\Tests\EmailValidator\Validation;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Egulias\EmailValidator\EmailLexer;
|
||||
use Egulias\EmailValidator\Warning\Comment;
|
||||
use Egulias\EmailValidator\Exception\CRNoLF;
|
||||
use Egulias\EmailValidator\Warning\CFWSNearAt;
|
||||
use Egulias\EmailValidator\Result\InvalidEmail;
|
||||
use Egulias\EmailValidator\Warning\CFWSWithFWS;
|
||||
@@ -23,8 +22,6 @@ use Egulias\EmailValidator\Warning\IPV6ColonStart;
|
||||
use Egulias\EmailValidator\Warning\IPV6Deprecated;
|
||||
use Egulias\EmailValidator\Warning\IPV6GroupCount;
|
||||
use Egulias\EmailValidator\Warning\IPV6DoubleColon;
|
||||
use Egulias\EmailValidator\Exception\ConsecutiveDot;
|
||||
use Egulias\EmailValidator\Exception\ExpectingDTEXT;
|
||||
use Egulias\EmailValidator\Validation\RFCValidation;
|
||||
use Egulias\EmailValidator\Result\Reason\NoLocalPart;
|
||||
use Egulias\EmailValidator\Result\Reason\AtextAfterCFWS;
|
||||
|
||||
Reference in New Issue
Block a user