Skip to content

Commit

Permalink
Fix PHP 7.4 support for 1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas authored and mlocati committed Aug 8, 2019
1 parent e7dacfc commit 6c9f1a0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
16 changes: 15 additions & 1 deletion src/Egulias/EmailValidator/EmailLexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,22 @@ class EmailLexer extends AbstractLexer

protected $previous;

private static $nullToken = array(
'value' => '',
'type' => null,
'position' => 0,
);

public function __construct()
{
$this->previous = $this->token = self::$nullToken;
}

public function reset()
{
$this->hasInvalidTokens = false;
parent::reset();
$this->previous = $this->token = self::$nullToken;
}

public function hasInvalidTokens()
Expand Down Expand Up @@ -122,8 +134,10 @@ public function getPrevious()
public function moveNext()
{
$this->previous = $this->token;
$hasNext = parent::moveNext();
$this->token = $this->token ?: self::$nullToken;

return parent::moveNext();
return $hasNext;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Egulias/EmailValidator/Parser/DomainPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ protected function doParseDomainPart()

$domain .= $this->lexer->token['value'];
$this->lexer->moveNext();
} while ($this->lexer->token);
} while (null !== $this->lexer->token['type']);

return $domain;
}
Expand Down
11 changes: 7 additions & 4 deletions src/Egulias/EmailValidator/Parser/LocalPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ public function parse($localPart)
$closingQuote = false;
$openedParenthesis = 0;

while ($this->lexer->token['type'] !== EmailLexer::S_AT && $this->lexer->token) {
if ($this->lexer->token['type'] === EmailLexer::S_DOT && !$this->lexer->getPrevious()) {
throw new \InvalidArgumentException('ERR_DOT_START');
while ($this->lexer->token['type'] !== EmailLexer::S_AT && null !== $this->lexer->token['type']) {
if ($this->lexer->token['type'] === EmailLexer::S_DOT) {
$previous = $this->lexer->getPrevious();
if (null === $previous['type']) {
throw new \InvalidArgumentException('ERR_DOT_START');
}
}

$closingQuote = $this->checkDQUOTE($closingQuote);
Expand Down Expand Up @@ -78,7 +81,7 @@ protected function parseDoubleQuote()

$this->lexer->moveNext();

while ($this->lexer->token['type'] !== EmailLexer::S_DQUOTE && $this->lexer->token) {
while ($this->lexer->token['type'] !== EmailLexer::S_DQUOTE && null !== $this->lexer->token['type']) {
$parseAgain = false;
if (isset($special[$this->lexer->token['type']]) && $setSpecialsWarning) {
$this->warnings[] = EmailValidator::CFWS_FWS;
Expand Down

0 comments on commit 6c9f1a0

Please sign in to comment.