Skip to content

Commit

Permalink
opened parenthesis converted to class field
Browse files Browse the repository at this point in the history
  • Loading branch information
whyte624 authored and egulias committed Oct 11, 2015
1 parent a7b3853 commit de448a3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/Egulias/EmailValidator/Parser/DomainPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ protected function doParseDomainPart()
}

if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
$this->parseComments($openedParenthesis);
$this->parseComments();
$openedParenthesis += $this->getOpenedParenthesis();
$this->lexer->moveNext();
$tmpPrev = $this->lexer->getPrevious();
if ($tmpPrev['type'] === EmailLexer::S_CLOSEPARENTHESIS) {
Expand Down
3 changes: 2 additions & 1 deletion src/Egulias/EmailValidator/Parser/LocalPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public function parse($localPart)
}

if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
$this->parseComments($openedParenthesis);
$this->parseComments();
$openedParenthesis += $this->getOpenedParenthesis();
}
if ($this->lexer->token['type'] === EmailLexer::S_CLOSEPARENTHESIS) {
if ($openedParenthesis === 0) {
Expand Down
19 changes: 11 additions & 8 deletions src/Egulias/EmailValidator/Parser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ abstract class Parser
{
protected $warnings = array();
protected $lexer;
protected $openedParenthesis = 0;

public function __construct(EmailLexer $lexer)
{
Expand All @@ -22,6 +23,12 @@ public function getWarnings()

abstract public function parse($str);

/** @return int */
public function getOpenedParenthesis()
{
return $this->openedParenthesis;
}

/**
* validateQuotedPair
*/
Expand All @@ -35,18 +42,14 @@ protected function validateQuotedPair()
$this->warnings[] = EmailValidator::DEPREC_QP;
}

/**
* @param int $openedParenthesis
* @return string the comment
*/
protected function parseComments(&$openedParenthesis = 0)
protected function parseComments()
{
$openedParenthesis++;
$this->openedParenthesis = 1;
$this->isUnclosedComment();
$this->warnings[] = EmailValidator::CFWS_COMMENT;
while (!$this->lexer->isNextToken(EmailLexer::S_CLOSEPARENTHESIS)) {
if ($this->lexer->isNextToken(EmailLexer::S_OPENPARENTHESIS)) {
$openedParenthesis++;
$this->openedParenthesis++;
}
$this->warnEscaping();
$this->lexer->moveNext();
Expand Down Expand Up @@ -164,7 +167,7 @@ protected function checkDQUOTE($hasClosingQuote)
return $hasClosingQuote;
}
$previous = $this->lexer->getPrevious();
if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous['type'] === EmailLexer::GENERIC) {
if ($previous['type'] === EmailLexer::GENERIC && $this->lexer->isNextToken(EmailLexer::GENERIC)) {
throw new \InvalidArgumentException('ERR_EXPECTING_ATEXT');
}

Expand Down

0 comments on commit de448a3

Please sign in to comment.